惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
Vulnerabilities – Threatpost
Cloudbric
Cloudbric
G
GRAHAM CLULEY
S
Securelist
Schneier on Security
Schneier on Security
Help Net Security
Help Net Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
Spread Privacy
Spread Privacy
P
Privacy International News Feed
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
T
Tailwind CSS Blog
博客园_首页
有赞技术团队
有赞技术团队
Simon Willison's Weblog
Simon Willison's Weblog
Stack Overflow Blog
Stack Overflow Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
T
Tor Project blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Attack and Defense Labs
Attack and Defense Labs
www.infosecurity-magazine.com
www.infosecurity-magazine.com
O
OpenAI News
J
Java Code Geeks
T
Tenable Blog
K
Kaspersky official blog
AWS News Blog
AWS News Blog
S
Security @ Cisco Blogs
The GitHub Blog
The GitHub Blog
T
Threatpost
月光博客
月光博客
H
Heimdal Security Blog
Security Latest
Security Latest
The Hacker News
The Hacker News
Y
Y Combinator Blog
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
C
Cisco Blogs
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
C
CERT Recently Published Vulnerability Notes
D
Docker
Google Online Security Blog
Google Online Security Blog
D
DataBreaches.Net
V
Visual Studio Blog
H
Help Net Security

博客园 - ji yang

页面点击分析工具设计与实现 使用FreeMind代替PowerPoint做演示 Velocity 2011大会归来 通过扩展属性为SqlServer的索引添加注释信息 memcached对中文key的支持 更安全的服务器:Windows账号权限修改监控 网站活跃用户统计的思路与设计 以服务的方式提供站点基础功能支持 fastdfs dotnet 客户端发布 go lang web项目的部署与发布 从设计图到HTML页面时的注意点 关于加班 关于Google App Engine 一个简单的Spring.net绑定例子 SOA中国路线图活动感受 文章被转载了 Asp.net中基类页的设计和使用 产品营销上的求同策略
safari的url地址转义问题
ji yang · 2011-05-10 · via 博客园 - ji yang

调用页面:

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title></title>
</head>
<body>
    
<a id="login" target="_blank">test</a>
</body>
<script type="text/javascript">
        
var name = "中文用户名";
        
var pass = "123";
        
var url = "test.ashx";
        url 
+= "?name=" + escape(name);
        url 
+= "&password=" + pass;
        document.getElementById(
"login").href = url;            
</script>
</html>

处理页面:

<%@ WebHandler Language="C#" Class="test" %>using System;
using System.Web;public class test : IHttpHandler {
    
    
public void ProcessRequest (HttpContext context) {
        
if (context.Request["name"== "中文用户名" && context.Request["password"== "123") {
            context.Response.Write(
"ok");
        } 
else {
            context.Response.Write(
"error");
        }
    }
 
    
public bool IsReusable {
        
get {
            
return false;
        }
    }

}

用safari浏览,传输到服务器端时,转义后的url会变成:

name=%25u4E2D%25u6587%25u7528%25u6237%25u540D&password=123

name=%u4E2D%u6587%u7528%u6237%u540D&password=123

可见,作为url传递时,safari把%也转义了,escape("%")正好等于 %25

这儿的解决方式是:

使用:encodeURI() 来转义,即按 UTF-8 来编码。

关于:

escape() encodeURI() encodeURIComponent() 的差别,可以看这篇文章:

javaScript中URL编码转换,escape() encodeURI() encodeURIComponent

escape() 方法:

采用ISO Latin字符集对指定的字符串进行编码。所有的空格符、标点符号、特殊字符以及其他非ASCII字符都将被转化成%xx格式的字符编码(xx等于该字符在字符集表里面的编码的16进制数字)。比如,空格符对应的编码是%20。unescape方法与此相反。不会被此方法编码的字符: @ * / +

encodeURI() 方法:

把URI字符串采用UTF-8编码格式转化成escape格式的字符串。不会被此方法编码的字符:! @ # $& * ( ) = : / ; ? + '

encodeURIComponent() 方法:

把URI字符串采用UTF-8编码格式转化成escape格式的字符串。与encodeURI()相比,这个方法将对更多的字符进行编码,比如 / 等字符。所以如果字符串里面包含了URI的几个部分的话,不能用这个方法来进行编码,否则 / 字符被编码之后URL将显示错误。不会被此方法编码的字符:! * ( )