2019独角兽企业重金招聘Python工程师标准>>>

使用的多是System.Web.Util.HttpEncoder对象。

分析System.Web.Util.HttpEncoder类。  HttpEncoder多使用System.Web.Util.HttpEncoderUtility类对象。

public static int HexToInt(char h)
{if ((h >= '0') && (h <= '9')){return (h - '0');}if ((h >= 'a') && (h <= 'f')){return ((h - 'a') + 10);}if ((h >= 'A') && (h <= 'F')){return ((h - 'A') + 10);}return -1;
} 
public static char IntToHex(int n)
{ if (n <= 9){ return (char) (n + 0x30);} return (char) ((n - 10) + 0x61);
}
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;
}
internal static string UrlEncodeSpaces(string str)
{ if ((str != null) && (str.IndexOf(' ') >= 0)){ str = str.Replace(" ", "%20");} return str;
}
public static unsafe void HtmlEncode(string value, TextWriter output)
{ if (value != null){ if (output == null){ throw new ArgumentNullException("output");} int num = IndexOfHtmlEncodingChars(value, 0); if (num == -1){ output.Write(value);} else { int num2 = value.Length - num; fixed (char* str = ((char*) value)){ char* chPtr = str; char* chPtr2 = chPtr; while (num-- > 0){ chPtr2++; output.Write(chPtr2[0]);} while (num2-- > 0){ chPtr2++; char ch = chPtr2[0]; if (ch <= '>'){ switch (ch){ case '&':{ output.Write("&amp;"); continue;} case '\'':{ output.Write("'"); continue;} case '"':{ output.Write("&quot;"); continue;} case '<':{ output.Write("&lt;"); continue;} case '>':{ output.Write("&gt;"); continue;}} output.Write(ch); continue;} if ((ch >= '\x00a0') && (ch < 'Ā')){ output.Write("&#"); output.Write(ch.ToString(NumberFormatInfo.InvariantInfo)); output.Write(';');} else { output.Write(ch);}}}}}
}
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;
}
protected internal virtual string UrlPathEncode(string value)
{ if (string.IsNullOrEmpty(value)){ return value;} int index = value.IndexOf('?'); if (index >= 0){ return (this.UrlPathEncode(value.Substring(0, index)) + value.Substring(index));} return HttpEncoderUtility.UrlEncodeSpaces(this.UrlEncodeNonAscii(value, Encoding.UTF8));
}

注意看这里。这就是差别。

int index = value.IndexOf('?');if (index >= 0){return (this.UrlPathEncode(value.Substring(0, index)) + value.Substring(index));}return HttpEncoderUtility.UrlEncodeSpaces(this.UrlEncodeNonAscii(value, Encoding.UTF8));

如果是path方法, 如果?号有任何值,则不再进行操作。直接传递。

转载于:https://my.oschina.net/mahaisong/blog/155611

解码转码---System.web.HttpUtility 对象分析相关推荐

  1. c#asp.net url 传递中文参数要使用 System.Web.HttpUtility.UrlEncode 而不能使用Server.UrlEncode...

    最近网站里的参数包括中文的例如: http://www.taiba/Tag%b0%ae%c7%e9.html 已开始使用 Server.UrlEncode来做的,但发现,有一些中文在url重写的是说找 ...

  2. 解决无法将类型为“System.Web.UI.WebControls.HiddenField”的对象强制转换为类型的错误...

    解决无法将类型为"System.Web.UI.WebControls.HiddenField"的对象强制转换为类型的错误 2008-01-04 16:14 本文章将解决: 1.解释 ...

  3. Owin的URL编码怎么搞?以前都是HttpUtility.UrlEncode之类的,现在连system.web都没了,肿么办?...

    Owin的URL编码怎么搞?以前都是HttpUtility.UrlEncode之类的,现在连system.web都没了,肿么办? 编码: Uri.EscapeDataString(name) 解码: ...

  4. Selenium自动化中DOM,XPATH,CSS定位Web页面对象的优劣性分析

    加速IE浏览器自动化执行效率:Selenium自动化中DOM,XPATH,CSS定位Web页面对象的优劣性分析 1.技术背景       在Web应用中,用户通过键盘在输入框中输入值和鼠标点击按钮,链 ...

  5. [置顶] 当前上下文不存在 ScriptManager 的原因分析以及解决方案 (System.Web.Extensions)...

    错误如下图: 当我们在写web程序的时候,有时候避免不了要再后台弹出一个提示框,在winform中我们可以用MssageBox() 类来实现,在web开发中,我们只能借助于javascript来实现了 ...

  6. 关于System.Web.Caching的“未将对象引用设置到对象的实例”错误

    初接触Asp.Net不久,想在后端做个缓存机制,于是使用了System.Web.Caching的Cache类. 使用部分的逻辑很简单,但是取值时总报错 private static Cache cac ...

  7. Spring源码阅读之bean对象的创建过程

    Spring源码阅读之bean对象的创建过程 ​ Spring是通过IOC容器来管理对象的,该容器不仅仅只是帮我们创建了对象那么简单,它负责了对象的整个生命周期-创建.装配.销毁.这种方式成为控制反转 ...

  8. System.Web.Caching.Cache类 缓存 各种缓存依赖

    原文:System.Web.Caching.Cache类 缓存 各种缓存依赖 Cache类,是一个用于缓存常用信息的类.HttpRuntime.Cache以及HttpContext.Current.C ...

  9. System.Web

    如果 using System.Web:还是调用不出来其中的类,请在引用的位子添加 System.Web  引用,有的版本不自带这个命名空间. 类: HttpResponse类       用于绘画验 ...

最新文章

  1. 关于C#泛型列表ListT的基本用法总结
  2. OpenCASCADE:OCCT应用框架OCAF之形状属性
  3. mysql的redo日志_MySQL redo与undo日志解析
  4. git 简易指南+常用命令
  5. 从易到难,写一个JavaScript加载器之一
  6. 代码注释掉还能执行_日志消息是可执行代码和注释
  7. 十三不香了?不止去掉刘海,iPhone14或改用QLC闪存:最高2TB容量
  8. 星巴克“啡快”宣布接入支付宝、口碑等阿里应用
  9. python map什么意思_Python中map是什么意思
  10. 静态文件之static+url控制系统(萌新笔记)
  11. Android 网易云IM开发
  12. coon.php连接,CoonClient.php
  13. 百度云文字识别 (AIPOcr)
  14. 在Win10下 用 Powershell 或 CMD 完成文件的 MD2 MD4 MD5 SHA1 SHA256 SHA384 SHA512 等哈希校验
  15. 一个故事贯穿设计模式小例子练习源码
  16. 马槊, 在古代是将领身份的象征
  17. 双十二苏州老百姓学会了数字人民币APP钱包注册及使用
  18. Unity游戏开发:3D冒险游戏项目实战
  19. 下载知网论文PDF版本
  20. 矩阵分析学习指导_如何系统地学习统计学,指导入门数据分析

热门文章

  1. 咱们程序员,能吵吵就别动手!现在靠说就可以编程,支持Java、Python等10种语言|免费...
  2. ACL 2020三大奖项出炉!知名学者夫妇曾先后获终身成就奖,时间检验奖回溯95年经典著作...
  3. 1分钟10万字大法:量子波动速读、蒙眼翻书穿针,这是席卷15省的最新智商税...
  4. Apollo 5.0,GitHub热榜第四
  5. Linux安装Composer
  6. Spring Boot项目利用MyBatis Generator进行数据层代码自动生成
  7. Fabric环境搭建
  8. Dockerfile基本语法
  9. CSS实现某元素hover时 所有兄弟节点样式改变
  10. Nginx主配置文件nginx.conf详细说明