再加上查询字符串签名 [英] Plus sign in query string

查看:174
本文介绍了再加上查询字符串签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#和asp.net创建web应用程序。我在查询字符串放在一个参数值与一个加号(+)号。但是,加号消失。

如何才能在查询字符串中的加号(+)没有消失?

请指教。

感谢。

编辑:增加了code。与UrlEn code

 字符串str = Server.UrlEn code(Requery.QueryString [新]);


解决方案

+ 标志具有查询字符串中的语义。它是用来重新present的空间。有查询字符串语义重要性的另一个特点是&安培; 这是用来分离各种 VAR =值对在查询字符串

大多数服务器端脚本会去code中的查询参数使用前,让 + 被正确地转换为一个空格。现在,如果你想有一个文字 + 是在查询字符串present,你需要指定%2B 代替。

在查询字符串

+ 标志是URL德coded到的空间。 %2B 查询字符串URL是德coded到一个+号。

请参阅

之间的区别

http://www.google.com/search?q=foo+bar

http://www.google.com/search?q=foo%2Bbar

在上面的例子中,谷歌的服务器脚本是用它们进行搜索的URL解码查询参数,然后

URL编码是什么,但符号后面跟特殊字符的将十六进制code。例如,我们知道, A 的十六进制code是0×41(十进制65)。试试这个:

http://www.google.com/search?q=%41

希望这是URL编码清晰。

所以,如果你想在 + 的迹象是,当一个JavaScript是获取一个URL preserved + 在查询参数标志和一个服务器端脚本后,URL解码它,你应该URL-CN code在URL中的查询参数使用发出HTTP GET请求之前,使所有<$将处理查询参数C $ C> + 标志将被转换为%2B 当请求到达服务器端脚本秒。现在,当服务器端脚本URL德codeS查询字符串,所有的%2B 的被转换回 + 的迹象这是你想要的。

请参阅如何连接在Javascript codeA网址?,了解如何进行URL连接code使用JavaScript的参数。

:从讨论中有简答题

 变种EN codedURL =htt​​p://example.com/foo.php?var=+ EN codeURIComponent(参数);

I have a webapp created using C# and asp.net. I placed a parameter value in the querystring with a plus(+) sign. But the plus sign disappear.

How can I include the plus sign(+) in the query string without disappearing?

Please advise.

Thanks.

Edit: added code with UrlEncode

string str = Server.UrlEncode(Requery.QueryString["new"]);

解决方案

+ sign has a semantic meaning in the query string. It is used to represent a space. Another character that has semantic importance in the query string is & which is used to separate the various var=value pairs in the query string.

Most server side scripts would decode the query parameters before using them, so that a + gets properly converted to a space. Now, if you want a literal + to be present in the query string, you need to specify %2B instead.

+ sign in the query string is URL-decoded to a space. %2B in the query string is URL-decoded to a + sign.

See the difference between

http://www.google.com/search?q=foo+bar

and

http://www.google.com/search?q=foo%2Bbar

In the above examples, Google's server script is URL-decoding the query parameters and then using them to do the search.

URL-encoding is nothing but % sign followed by the hex-code of the special character. For example, we know that the hex code of A is 0x41 (decimal: 65). Try this:

http://www.google.com/search?q=%41

Hope this makes URL-encoding clear.

So, if you want the + sign to be preserved when a JavaScript is fetching a URL with + signs in its query parameters and a server side script would process the query parameters after URL-decoding it, you should URL-encode the query parameters in the URL before using issuing the HTTP get request so that all + signs are converted to %2B's when the request reaches the server side script. Now when the server side script URL-decodes the query string, all %2B's gets converted back to + signs which is what you want.

See How to encode a URL in Javascript? to learn how to URL-encode the parameters using JavaScript. Short answer from the discussion there:

var encodedURL = "http://example.com/foo.php?var=" + encodeURIComponent(param);

这篇关于再加上查询字符串签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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