asp .net query string encoding and decoding

。_饼干妹妹 提交于 2019-11-29 10:56:27

You'll need to encode the URL first, using URLEncode(). + in URL equals a space so needs to be encoded to %2b.

string paymentId = Server.UrlEncode("6++7d6CZRKY=");
// paymentId = 6%2b%2b7d6CZRKY%3d

And now

string result = Request.QueryString["paymentId"].ToString();
//result = 6++7d6CZRKY=

However

string paymentId = Server.UrlEncode("6  7d6CZRKY=");
//paymentId looks like you want it, but the + is a space -- 6++7d6CZRKY%3d

string result = Request.QueryString["paymentId"].ToString();
//result = 6 7d6CZRKY=
Francis Gagnon

There is some info on this here: Plus sign in query string.

But I suppose you could also use a regular expression to get your parameter out of the query string. Something like this:

string queryString = HttpContext.Current.Request.QueryString.ToString();
string paramPaymentID = Regex.Match(queryString, "paymentID=([^&]+)").Groups[1].Value;

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

I hope this help you

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