- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
URLEncode converts characters as follows:
- Spaces ( ) are converted to plus signs (+).
- Non-alphanumeric characters are escaped to their hexadecimal representation.
application/x-www-form-urlencoded
This is the default content type. Forms submitted with this content type must be encoded as follows:
Control names and values are escaped. Space characters are replaced by '+', and then reserved characters are escaped as described in RFC1738, section 2.2: Non-alphanumeric characters are replaced by '%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., '%0D%0A').
The control names/values are listed in the order they appear in the document. The name is separated from the value by '=' and name/value pairs are separated from each other by '&'.
最佳答案
好了,您链接到的文档是针对IIS 6 Server.UrlEncode的,但是您的标题似乎是关于.NET System.Web.HttpUtility.UrlEncode的。使用Reflector之类的工具,我们可以看到后者的实现并确定它是否符合W3C规范。
这是最终被调用的编码例程(请注意,它是为字节数组定义的,而其他占用字符串的重载最终会将这些字符串转换为字节数组并调用此方法)。您将为每个控件名称和值调用此函数(以避免转义用作分隔符的保留字符= &
)。
protected internal virtual byte[] UrlEncode(byte[] bytes, int offset, int count)
{
if (!ValidateUrlEncodingParameters(bytes, offset, count))
{
return null;
}
int num = 0;
int num2 = 0;
for (int i = 0; i < count; i++)
{
char ch = (char) bytes[offset + i];
if (ch == ' ')
{
num++;
}
else if (!HttpEncoderUtility.IsUrlSafeChar(ch))
{
num2++;
}
}
if ((num == 0) && (num2 == 0))
{
return bytes;
}
byte[] buffer = new byte[count + (num2 * 2)];
int num4 = 0;
for (int j = 0; j < count; j++)
{
byte num6 = bytes[offset + j];
char ch2 = (char) num6;
if (HttpEncoderUtility.IsUrlSafeChar(ch2))
{
buffer[num4++] = num6;
}
else if (ch2 == ' ')
{
buffer[num4++] = 0x2b;
}
else
{
buffer[num4++] = 0x25;
buffer[num4++] = (byte) HttpEncoderUtility.IntToHex((num6 >> 4) & 15);
buffer[num4++] = (byte) HttpEncoderUtility.IntToHex(num6 & 15);
}
}
return buffer;
}
public static bool IsUrlSafeChar(char ch)
{
if ((((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z'))) || ((ch >= '0') && (ch <= '9')))
{
return true;
}
switch (ch)
{
case '(':
case ')':
case '*':
case '-':
case '.':
case '_':
case '!':
return true;
}
return false;
}
a-z A-Z 0-9 ()*-._!
%HH
Thus, only alphanumerics, the special characters "$-_.+!*'(),", and
reserved characters used for their reserved purposes may be used
unencoded within a URL.On the other hand, characters that are not required to be encoded
(including alphanumerics) may be encoded within the scheme-specific
part of a URL, as long as they are not being used for a reserved
purpose.
UrlEncode
允许的一组URL安全字符是RFC1738中定义的特殊字符的子集。也就是说,即使规范说它们安全,也会缺少字符
$,
并由
UrlEncode
编码。由于可以不经编码(而不是必须)使用它们,因此它仍然符合对它们进行编码的规范(第二段明确指出了这一点)。
CR LF
序列,则将转义
%0D%0A
。但是,如果输入只有
LF
,则将转义
%0A
(因此,此例程中没有换行符的规范化处理)。
$,
进行编码,并且调用方负责在输入中提供适当的标准化换行符。
关于.net - HttpUtility.UrlEncode是否符合 'x-www-form-urlencoded'的规范?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3208555/
我正在尝试开发一个安全的 Web 应用程序,它可以接受表单数据,将其编码到数据库中以消除跨站点脚本问题,然后在其他网页上很好地格式化它。 正在使用 对表单数据进行编码 HttpUtility.Html
我尝试在 wp8.1 中开发某些应用程序时找不到 HttpUtility.UrlDecode 或 HttpUtility.UrlEncode。我包含了 System.net 命名空间。这是从 8.1
我在下载文件时遇到问题,下载时将所有空格替换为下划线。 基本上我在这里遇到了问题: Response.AddHeader("Content-Disposition", "attachment;
我正在使用这两行代码作为反向代理 reverseProxy:=httputil.NewSingleHostReverseProxy(url) reverseProxy.ServeHTTP(rw, re
我在编译 C# 应用程序时遇到此错误。看起来像是一个微不足道的错误,但我无法解决它。 我的设置是 Windows 7 64 位。 Visual-Studio 2010 C# 表示 B2Rel。 我添加
我正在尝试提取带有 + 特殊字符的电子邮件,但由于某种原因 ParseQueryString 跳过它: namespace ParsingProblem { class Pro
我必须对一个字段进行编码,以确保脚本注入(inject)的安全。 我知道我可以使用 HttpUtility.HtmlEncode 和 Decode,但是这种用于 HI-ASCII 字符的方法超出了数据
我是 Android 编程新手,我一直在学习教程以在我的应用程序中获取实时 Twitter 提要。我在我的 String twitterTweets = httpUtil.getHttpRespons
我正在尝试使用 HttpUtility.UrlEncode 对以下字符串进行编码; 1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "userbouquet.dbe01.tv" OR
我正在使用 facebook-java-api 为我的 Web 应用程序实现 facebook connect。我实际上正在遵循此 site 中的教程 我已经编写了一个 servlet 来实现教程中给
我正在尝试对要发送到网络服务进行处理的参数进行编码。我从一个带有参数的命令开始,例如: TransportProviderConfirmation/68,Akal Singh,+97254494486
当 .net 在您请求时已经解码查询字符串时,HttpUtility.UrlDecode 有什么意义。 这是经典 ASP 的后遗症还是我遗漏了什么? 最佳答案 如果您从其他来源收到 UrlEncode
我收到以下错误: The name 'HttpUtility' does not exist in the current context 我正在构建一个 winform 应用程序,这是我使用 fra
这可能是个愚蠢的问题,但每次都会让我感到困惑。 HttpUtility 有方法 HtmlDecode 和 UrlDecode。这两种方法是否解码我可能发现的任何内容(Html/Http 相关)?我什么
我有一个返回 View 的 ASP.NET MVC Controller 。在这个 View 中,我创建了一些 html。例如 @Html.ActionLink(HttpUtility.HtmlDec
我使用此代码发送彩信,所有参数都正确,但连接被拒绝。并且网络已在移动彩信上连接。 HttpUtils 是一个来自此处下载的库的类:https://github.com/android/platform
我处在一个我有一些路径的情况下。此路径可能类似于“jadajada.com/My Site.html”。 我使用 HttpUtility.UrlEncode 对 url 进行编码,这很棒。但是,我遇到
有人能给我解释一下 ParseQueryString 的这种行为吗: var qs = HttpUtility.ParseQueryString("/Site/controller/Index?dat
我试图在我的 VB.NET 项目中调用静态 HttpUtility.UrlEncode,但 IDE 无法识别该类,表示它未声明。 我已将命名空间 System.Net 和 System.Web 导入到
如何在窗口应用程序中使用 httpUtility.encode 和 decode。我实现了一个窗口应用程序。此应用程序使用 Web 请求到 Web 服务器。 Web 服务器响应 http 编码版本。那
我是一名优秀的程序员,十分优秀!