0
点赞
收藏
分享

微信扫一扫

,decodeURIComponent() ,encodeURICompon加密解密js对url和字符串,解码,编码,解密,加密

一世独秀 2022-06-20 阅读 76

c#对js的

encodeURI() 编码 decodeURI()解码 ,

escape() 编码unescape()解码,

encodeURIComponent()编码 decodeURIComponent() 解码,

字符串加密解密

第一种

Url编码: 

JS方法:encodeURI("你好")
结果:"%E4%BD%A0%E5%A5%BD"

c#方法:HttpUtility.UrlEncode("你好")
结果:"%e4%bd%a0%e5%a5%bd"

Url解码:

JS方法:decodeURI("%e4%bd%a0%e5%a5%bd")
结果:"你好"

c#方法:HttpUtility.UrlDecode("%E4%BD%A0%E5%A5%BD")
结果:"你好"

第二种

编码:

JS方法:escape("你好")
结果:"%u4F60%u597D"

c#方法:HttpUtility.UrlEncodeUnicode("你好")
结果:"%u4f60%u597d"

解码:

JS方法:unescape("%u4f60%u597d")
结果:"你好"

c#方法:HttpUtility.UrlDecode("%u4F60%u597D")
结果:"你好"

第三种

对应JS 的decodeURIComponent() 和 encodeURIComponent()

JS方法

var str3="https://mp.csdn.net/"; 
var _str3=encodeURIComponent(str3);
document.write("<br/><hr/><br/> <h1>第三种 URL的编码与解码 decodeURIComponent() 和 encodeURIComponent()</h1>")
document.write("编码:"+_str3+ "<br>")
document.write("解码:"+decodeURIComponent(_str3)+ "<br>")
编码:https%3A%2F%2Fmp.csdn.net%2F
解码:https://mp.csdn.net/

c#方法 

string _URL = "https://mp.csdn.net/";//URL 原文
string URL = HttpUtility.UrlEncode(_URL); //编码url
string resultURL = HttpUtility.UrlDecode(URL); //解码url
编码url:https%3a%2f%2fmp.csdn.net%2f
解码url:https://mp.csdn.net/

举报

相关推荐

0 条评论