论坛首页 编程语言技术论坛

Server.UrlEncode与HttpUtility.UrlEncode的区别有哪些

浏览 2379 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2017-03-15  

一、HttpUtility.UrlEncode 方法

 

1、public static string UrlEncode(byte[])

将字节数组转换为已编码的 URL 字符串。

 

2、public static string UrlEncode(string)

对 URL 字符串进行编码。
 

3、public static string UrlEncode(string, Encoding)

使用指定的编码对象对 URL 字符串进行编码。
 

4、public static string UrlEncode(byte[], int, int)

从数组中的指定位置开始一直到指定的字节数为止,将字节数组转换为 URL 编码的字符串。
 

 

 

二、Server.UrlEncode方法

 

1、public string UrlEncode(string)

对字符串进行 URL 编码,并返回已编码的字符串。
 

2、public void UrlEncode(string, TextWriter)

URL 对字符串进行编码,并将结果输出发送到 TextWriter 输出流。
 

 

 

三、Server.UrlEncode与HttpUtility.UrlEncode的区别

 

1、HttpUtility.UrlEncode,HttpUtility.UrlDecode是静态方法,而Server.UrlEncode,Server.UrlDecode是实例方法。


2、Server是HttpServerUtility类的实例,是System.Web.UI.Page的属性。

 

3、Server.UrlEncode的编码方式是按照本地程序设置的编码方式进行编码的,而HttpUtility.UrlEncode是默认的按照utf-8格式进行编码的,如果需要指定HttpUtility.UrlEncode的编码方式,则需要:HttpUtility.UrlEncode("学习也休闲", Encoding.GetEncoding("gb2312"));

 

 

参考资料:Server.UrlEncode与HttpUtility.UrlEncode的区别有哪些 http://www.studyofnet.com/news/1130.html

 

论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics