Arabic QueryString problem (???? in the value)

╄→гoц情女王★ 提交于 2019-12-12 08:57:03

问题


I am sending an arabic value in a querystring, when retrieving it on the server, the value is erroneous and is replaced by quotation marks (????). for example: http://server/mypage.aspx?qs=مرحبا the value of Request.QueryString("qs") is ?????

Note that Response.Write('مرحبا') executes correctly.

Any idea about this querystring problem?

Thanks.


回答1:


Just URL Encode the arabic string and it should work fine.

Edit: You must URL Encode the string before putting it in the querystring.

For instance, if you were to url encode the space character, it will appear as %20 in your querystring, like this:

http://foo.com/dosomething?param1=hello%20world

Then when you read param1 you URL Decode it, and you get the string "hello world"

You could also URL Encode every single character but for regular characters it's pointless.




回答2:


I had a similar problem and solved it by putting the following line in my web.config file:

<globalization fileEncoding="windows-1256" 
    requestEncoding="windows-1256" responseEncoding="windows-1256"/>"

And this in the head section of my HTML page:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">



回答3:


I sent an Arabic text in my query string

and when I resieved this string it was Encoded

after Server.UrlDecode

 departmentName = Server.UrlDecode(departmentName);

it back again to arabic

so just use Server.UrlDecode(encodedString);

Hope this help you




回答4:


The Non english characters can't be passed without being encoded ,

so you need to encode the value before you redirect to the target page as follows:

string text="مرحبا";
text=Server.UrlEncode(text);
string url="http://server/mypage.aspx?qs="+text;
Response.Redirect(url);


来源:https://stackoverflow.com/questions/3091550/arabic-querystring-problem-in-the-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!