. NET get URL Chinese parameter value of garbled problem Solving method Summary _ Practical skills

Source: Internet
Author: User
Tags urlencode

This article summarizes the analysis. NET gets the method of solving the garbled problem of the URL Chinese parameter value. Share to everyone for your reference, specific as follows:

Workaround:

1. Set up Web.config file

<system.web>
<globalization requestencoding= "gb2312" responseencoding= "gb2312" culture= "ZH-CN" fileencoding= "gb2312"/>
</system.web>

2. Before passing the Chinese language, the Chinese parameters to be passed are encoded and decoded at the time of receiving.

String Name = "Chinese parameters";
Response.Redirect ("B.aspx?") Name= "+server.urlencode (Name));

String Name = request.querystring["name"];
Response.Write (Server.urldecode (Name));

3.JS Pass Chinese parameter:

function Gourl () {
var Name = ' Chinese parameter ';
Location.href = "B.aspx?" Name= "+escape (Name);
}

String Name = request.querystring["name"];
Response.Write (Server.urldecode (Name));

Summarize:

Generally speaking. You can set the Web.config file. But if you use JavaScript to invoke the WebService method (pass the Chinese parameter to the WebService). Setting the Web.config file appears to be invalid.

or by:

Response.Redirect ("test1.aspx?111=" +system.web.httputility.urlencode ("Chinese Republic of China"));
Recommended to use the last if it is from other pages to get Chinese parameters are not garbled, it is more simple
string message = "http://localhost/Test/test1.aspx?111=" + System.Web.HttpUtility.UrlEncode ("Chinese Republic of China");

http

You want to get the address of the return value of a page "
//Send request
HttpWebRequest myhttpwebrequest = (HttpWebRequest) webrequest.create (message);
Accept Request
HttpWebResponse Myhttpwebresponse = (HttpWebResponse) myhttpwebrequest.getresponse ();
Stream Receivestream = Myhttpwebresponse.getresponsestream ();
StreamReader Readstream = new StreamReader (Receivestream, System.Text.Encoding.GetEncoding ("GB2312"));
This is the return result for the return value of the page to be fetched
returnvalue = Readstream.readtoend ();

More interested readers of asp.net related content can view the site topics: "asp.net operation JSON tips summary", "asp.net string operation tips Summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", " asp.net Ajax Skills Summary topic and the "ASP.net cache operation skills Summary."

I hope this article will help you to ASP.net program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.