是否UrlDe code手柄加号(+)是否正确? [英] Does UrlDecode handle plus (+) correctly?

查看:180
本文介绍了是否UrlDe code手柄加号(+)是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 RFC 2396

  

加号+,美元$和逗号   ,字符已被加入到
  那些在保留属性,因为   它们被视为在为保留   查询组件。

事实上,搜索这个网站的加号+逗号,美元$,你会得到

<一个href="http://stackoverflow.com/search?q=plus+%2B+comma+,+dollar+">http://stackoverflow.com/search?q=plus+%2B+comma+,+dollar+$

Plus是只连接$ C $的cd(由应用程序),当它不被使用作为一个分隔符。

但是,随着其他人观察,.NET的 UrlDe code 函数将加空间。当指定了此行为?

解决方案
  

如果指定了这种行为?

借助 HTML 规范,奇怪的是。

UrlDe code 是一种误导性的名字命名。

+ 只表示在应用程序/ x-WWW的形式urlen codeD 数据空间作为定义的HTML;也就是说,无论是在表单POST提交请求体或?网址查询部分。这是一种特殊情况!在其他地方,在URL加只是一个加​​号。

  http://www.example.com/path+path/x?query+name=query+value
 

在此URL参数查询名称设置为查询值。它可以通过在GET的形式提交该表单域生成:

 &LT;输入名称=查询名称值=查询值&GT;
 

不过,该文件夹的名称是从字面上路径+路径。没有足够的空间。

由于这是混乱和潜在的模棱两可,最好的办法是始终EN code空格 20%。您可以使用 UrlPathEn code 做,在.NET。这同样适用于URL和路径的两个查询部分

According to RFC 2396,

The plus "+", dollar "$", and comma "," characters have been added to
those in the "reserved" set, since they are treated as reserved within the query component.

Indeed, search this site for "plus + comma , dollar $", and you get

http://stackoverflow.com/search?q=plus+%2B+comma+,+dollar+$

Plus is only encoded (by the application) when it's not being used as a delimiter.

But as others have observed, .NET's UrlDecode function converts plus to space. Where is this behavior specified?

解决方案

Where is this behavior specified?

The HTML spec, curiously enough.

UrlDecode is kind of misleadingly named.

+ only stands for a space in application/x-www-form-urlencoded data as defined by HTML; that is, either in a form POST submission request body or in the ?query part of the URL. This is a special case! Elsewhere in the URL a plus is just a plus.

http://www.example.com/path+path/x?query+name=query+value

In this URL the parameter query name is set to query value. It might be generated by submitting this form field in a GET form:

<input name="query name" value="query value">

However, the folder name is literally path+path. No space.

Because this is confusing and potentially ambiguous, the best approach is always to encode spaces to %20. You can do that in .NET using UrlPathEncode. This works equally well in both the query part of the URL and the path.

这篇关于是否UrlDe code手柄加号(+)是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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