- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
有什么区别
HttpUtility.UrlPathEncode(params);
和
HttpUtility.UrlEncode(params);
我查看了 MSDN 页面
https://msdn.microsoft.com/en-us/library/system.web.httputility.urlpathencode(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/system.web.httputility.urlencode(v=vs.110).aspx
但它只告诉你不要使用 UrlPathEncode,并没有告诉你有什么区别。
最佳答案
不同之处在于一个编码字符串的 Url 和一个编码来自 Url 的路径部分(这意味着查询字符串之前的 url 部分),这是它的实现方式:
/// <summary>Encodes a URL string.</summary>
/// <returns>An encoded string.</returns>
/// <param name="str">The text to encode. </param>
public static string UrlEncode(string str)
{
if (str == null)
{
return null;
}
return HttpUtility.UrlEncode(str, Encoding.UTF8);
}
这里是 UrlPathEncode 的实现:
/// <summary>Encodes the path portion of a URL string for reliable HTTP transmission from the Web server to a client.</summary>
/// <returns>The URL-encoded text.</returns>
/// <param name="str">The text to URL-encode. </param>
public static string UrlPathEncode(string str)
{
if (str == null)
{
return null;
}
int num = str.IndexOf('?'); // <--- notice this
if (num >= 0)
{
return HttpUtility.UrlPathEncode(str.Substring(0, num)) + str.Substring(num);
}
return HttpUtility.UrlEncodeSpaces(HttpUtility.UrlEncodeNonAscii(str, Encoding.UTF8));
}
并且 msdn 还声明了 HttpUtility.UrlEnocde
:
These method overloads can be used to encode the entire URL, including query-string values.
关于c# - UrlPathEncode 与 UrlEncode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35887126/
我有这个: file://localhost/Volumes/Untitled%20RAID%20Set%201/Callum/iTunes/Music/Steppenwolf/Steppenwolf
MSDN page for UrlPathEncode指出不应使用 UrlPathEncode,我应该改用 UrlEncode。 Do not use; intended only for brows
我有带空格的 Url,想用 %20 替换空格(转义)。 UrlPathEncode 应该这样做,但它不适用于下面有空格的 url。有人可以解释为什么它不起作用吗? System.Web.HttpUti
有什么区别 HttpUtility.UrlPathEncode(params); 和 HttpUtility.UrlEncode(params); 我查看了 MSDN 页面 https://msdn.
我正在尝试对我的 Silverlight 项目中的 URL 中的 Unicode 字符进行编码。我想使用 HttpUtility.UrlPathEncode (Source) 但是,这个 版本的 Ht
HttpServerUtility.UrlPathEncode有什么区别和 HttpServerUtility.UrlEncode ?我什么时候应该选择一个? 最佳答案 更新:从 4.5 开始,根据
为什么 .NET 的文档为 HttpUtility.UrlPathEncode对于 .NET 4.5 状态 Do not use; intended only for browser compatib
我找到了 a brilliant example使用 HTMLAgilityPack 的 HTML sanitizer 。在代码中,使用了 Microsoft.Security.Application
在最近的一个项目中,我有幸解决了一个错误,该错误涉及文件名中有空格时无法加载图像。我想“多么简单的问题,我会UrlEncode()它!”但是,不!只需使用 UrlEncode()没有解决问题。 新问题
我是一名优秀的程序员,十分优秀!