• 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、两者都会如下转换字符:空格会被转换为加号、非字母数字字符会被转换为他们的十六进制表现形式。

  • 相关阅读:
    eclipse用法和技巧
    eclipse常用快捷键集锦
    移动端input的虚拟键盘影响布局
    使用github page + Hexo搭建个人博客折腾记
    javascript数组的排序(sort,冒泡)
    响应式布局与媒体查询
    css属性选择器诸如Class^=,Class*= ,Class$=释义
    怎么预览 GitHub 项目里的网页或 Demo
    常见浏览器的兼容问题(一)
    jQuery常用交互效果
  • 原文地址:https://www.cnblogs.com/coderblog/p/9067700.html
Copyright © 2020-2023  润新知