当下载东西需要用url传一个值时,用encodeURI两次之后,有的时候用迅雷下载会报不合法的RUL错误

阅读更多
在编程时,下载东西的时候,往往需要往后台传一个或者几个值,当这个值中包含汉字或者特殊字符时,往往需要
var url = url;
url=encodeURI(url); 
url=encodeURI(url);



但是有的时候,比如这个值中包含“%”时,下载的时候,当用迅雷下载的时候,有的时候会报一个不合法的URl错误,

这是因为迅雷的编码方式和一般的IE不一样,导致它不认识这个URL

这个时候,你只要把URl“?”后面传得东西用encodeURIComponent转换下,然后在后台把传过去的东西专程UTF-8格式的就好了

比如:url=url+'user!downLoad.action?name=hello%word';
这时候你只需要这样来用
var str = encodeURIComponent('user!downLoad.action?name=hello%world');
url = url+str;



然后在后台这样下
String name = request.getParameter("name");
name = new String(name.getBytes("ISO-8859-1"),"utf-8");	

这样就行了

你可能感兴趣的:(无效url,encodeuri,迅雷)