分享

关于java的URL编码的问题(URLencode,encode)

 昵称23020986 2015-04-20

今天看公司项目的代码,对图片发送异步请求的URL的编码问题,看了看,又查了一些资料,希望能对URL编码有疑惑的人了解一下吧。 AAAAAAAAAAAAAAAA:首先我是用java的URLencode.encode方法对其进行编码的。


它的说明是
 Encodes a given string s in a x-www-form-urlencoded string using the specified encoding schemeenc. All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9') and characters '.', '-', '*', '_' are converted into their hexadecimal value prepended by '%'. For example: '#' -> #. In addition, spaces are substituted by '+' BBBBBBBBBBBBBBB:但是呢URL传输需要字符串的规则是: 1:Characters in the unreserved character set as defined by(ALPHA, DIGIT, "-", ".", "_", "~") MUST NOT be encoded. 2: All other characters MUST be encoded. 3:The two hexadecimal characters used to represent encoded characters MUST be upper case. 不知道大家看出来没有有何区别,首先URLencode.encode 是'.', '-', '*', '_'符号不编码,而URL传输需要字符串是 "-", ".", "_", "~"不编码。


那么可以这样的 String URL="www.baidu.com"; String ENCODING="utf-8"; String strURL= URLEncoder.encode(URL, ENCODING).replace("*","*").replace("~", "~").replace("+"," ");

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多