&QUOT + QUOT;在querystring中用空格替换的符号 [英] "+" sign getting replaced with space in querystring

查看:160
本文介绍了&QUOT + QUOT;在querystring中用空格替换的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从URL中获得了包含编码数据的点击。我遇到过这样一种情况:这个数据有+符号被空格取代而我不希望它发生。



示例网址:http:/ /xyz.test.com//samplepage.aspx?msg=AUdAR0JGRERBWCMZIxYmJR8fTRY+JR5DRRkxQiA4RUQ=



以上网址通过第三方应用程序发送给用户。



我尝试了什么:



我使用过Server.UrlEncode(Request.QueryString) [REF]);

它不是用空格替换+符号,而是用%3d替换=符号。



我想用替换功能用+代替空格。但加密数据可以是任何东西。还有另一种方法可以避免这种行为。

I am getting a hit from URL which contain Encoded data. I have came across a situation where this data had + sign which is getting replaced with space and I don't want it to happen.

Sample URL: http://xyz.test.com//samplepage.aspx?msg=AUdAR0JGRERBWCMZIxYmJR8fTRY+JR5DRRkxQiA4RUQ=

Above URL is sent to users through a third party application.

What I have tried:

I have used Server.UrlEncode(Request.QueryString["REF"]);
It is not replacing + sign with space, but it is replacing "=" sign with %3d.

I thought to use "replace" function to replace "space" with "+". But encrypted data can be anything. Is there another way to avoid this behavior.

推荐答案

在url空间中的设计(并且最初)应编码为+而不是%20 ...

所以解决方案是 - 自己编码网址,就像你做的那样...

浏览器会很清楚,不会改变数据...

另一个 - 可能不太优选 - 选项是仅对base64编码数据(msg =之后的部分)。在这种情况下,您将不得不手动解码...
By design (and originally) in url space should be encoded to + and not to %20...
So the solution is - encode the url by yourself, just as you have done...
It will be clear to browser and will not change the data...
An other - probably less preferable - option is to base64 encode your data only (the part after the msg=). In this case you will have to decode manually...


您需要在生成\ redirect到网址时对msg值进行编码。



You need to encode the msg value when you generate\redirect to the url.

string url = string.Format("samplepage.aspx?msg={0}",
    System.Web.HttpUtility.UrlEncode("AUdAR0JGRERBWCMZIxYmJR8fTRY+JR5DRRkxQiA4RUQ="));


这篇关于&QUOT + QUOT;在querystring中用空格替换的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆