两者之间有什么区别:
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 )
Run Code Online (Sandbox Code Playgroud)
结果是:
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
Run Code Online (Sandbox Code Playgroud)
在测试时,我得到前两个相同的结果,所以我可以安全地假设UTF8是默认值,除非指定,或者可以在不同的系统上有所不同吗?
我有一些unicode转义序列的示例,如下所示:
%u00e9(é)
相当确定paypal在他们的IPN请求中发送了它.为什么.NET不像这样编码?
小智 7
HttpUtility.UrlEncode Method (String)Reflector中方法的源代码:
public static string UrlEncode(string str)
{
if (str == null)
{
return null;
}
return UrlEncode(str, Encoding.UTF8);
}
Run Code Online (Sandbox Code Playgroud)
对于你的问题:
所以我可以安全地假设UTF8是默认值,除非指定
是的你可以.