C# HttpUtility.UrlEncode标准编码与指定编码?

C# HttpUtility.UrlEncode标准编码与指定编码?,c#,.net,urlencode,C#,.net,Urlencode,以下两者之间的区别是什么: HttpUtility.UrlEncode("some string with é and β and stuff") HttpUtility.UrlEncode("some string with é and β and stuff", Encoding.UTF8) HttpUtility.UrlEncode( "some string with é and β and stuff", Encoding.Default ) 结果是: some+string+wit

以下两者之间的区别是什么:

HttpUtility.UrlEncode("some string with é and β and stuff")
HttpUtility.UrlEncode("some string with é and β and stuff", Encoding.UTF8)
HttpUtility.UrlEncode( "some string with é and β and stuff", Encoding.Default )
结果是:

some+string+with+%c3%a9+and+%ce%b2+and+stuff
some+string+with+%c3%a9+and+%ce%b2+and+stuff
some+string+with+%e9+and+%df+and+stuff
在测试时,我得到的前两个结果是相同的,因此我可以安全地假设UTF8是默认值,除非指定,或者在不同的系统上可能会有所不同

我看到过一些unicode转义序列的示例,如下所示:

%u00e9(é)


相当肯定paypal会在他们的IPN请求中发送这些信息。为什么.NET不这样编码?

反射程序中方法
HttpUtility.UrlEncode方法(字符串)
的源代码:

public static string UrlEncode(string str)
{
    if (str == null)
    {
        return null;
    }
    return UrlEncode(str, Encoding.UTF8);
}
关于你的问题:

因此,我可以安全地假设UTF8是默认值,除非指定


是的,您可以。

是的,您可以根据上面的示例安全地假设UTF8是默认值。请记住,.NET的默认编码由操作系统的底层代码页决定


您在PayPal中看到的“%u00e9”示例实际上是用于编码Unicode字符的示例。根据维基百科的说法,W3C拒绝了这个实现

您还问到“或者在不同的系统上会有所不同?”-Mono使用相同的UTF8。但是微软应该在MSDN中声明默认的编码方式。每个人都可能认为默认值是编码。默认值好的,非常彻底的回答,谢谢。是的,编码。默认值实际上意味着它将是“默认值”。实际上,发送它的不是paypal。似乎ASP.NET将其转换为其Request.Form集合中的非标准实现。原始数据:&address_street=%C3%A5lderstigen,请求。表单数据=&address_street=%u00e5lderstigen,DOH!默认情况下,HttpUtility.UrlEncode方法使用UTF-8编码。因此,使用UrlEncode方法提供的结果与使用UrlEncode方法并将UTF8指定为第二个参数相同。