zoukankan      html  css  js  c++  java
  • Server.UrlEncode与HttpUtility.UrlEncode的区别

    一、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 编码的字符串。
     

    如果在js 传参调用时对应的js编码与解码为

    escape     unescape

    二、Server.UrlEncode方法 

    1、public string UrlEncode(string)

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

    2、public void UrlEncode(string, TextWriter)

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

    如果在js 传参调用时对应的js编码与解码为

    endcodeURLComponent     decodeURLComponent()

    三、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"));

    4、两者都会如下转换字符:空格会被转换为加号、非字母数字字符会被转换为他们的十六进制表现形式。

  • 相关阅读:
    MySQL中B+树索引的使用
    MySQL测试环境遇到 mmap(xxx bytes) failed; errno 12解决方法
    MySQL中Cardinality值的介绍
    MySQL Online DDL
    像编程一样写文章—Markdown
    并发模型—共享内存模型(线程与锁)示例篇
    并发模型之——共享内存模型(线程与锁)理论篇
    并发模型之——基本概念
    通讯协议之——字节序
    IntelliJ IDEA14.1中java项目Maven中没有配置JDK时的问题
  • 原文地址:https://www.cnblogs.com/coderblog/p/9067700.html
Copyright © 2011-2022 走看看