如上图所示,阿里云的PercentEncode 转换! 为 %21php
PercentEncode 源码为:html
package com.aliyuncs.auth; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; public class AcsURLEncoder { public final static String URL_ENCODING = "UTF-8"; public static String encode(String value) throws UnsupportedEncodingException { return URLEncoder.encode(value, URL_ENCODING); } public static String percentEncode(String value) throws UnsupportedEncodingException{ return value != null ? URLEncoder.encode(value, URL_ENCODING).replace("+", "%20") .replace("*", "%2A").replace("%7E", "~") : null; } }
上图代表的确没有转义!(感叹号)java
C#中URLEncode,C#中有两种URLEncode,WebUlitity 和 HttpUlitityweb
[TestFixture] public class TestUlities { [Test] public void Test() { var url = @"http://img05.taobaocdn.com/bao/uploaded/TB2BVKlfFXXXXarXXXXXXXXXXXX_!!111708970-0-saturn_solar.jpg"; var webUrlEncode = WebUtility.UrlEncode(url); var httpUrlEncode = HttpUtility.UrlEncode(url); } }
发现都没有转义!(感叹号)工具
In general URIs as defined by RFC 3986 (see Section 2: Characters) may contain any of the following characters:ui
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=`.
Any other character needs to be encoded with the percent-encoding (
%
hh
). Each part of the URI has further restrictions about what characters need to be represented by an percent-encoded word.阿里云
使用如下代码URLEncode 来进行URLEncodeurl
public class AliUrlEncodeHelper { public static string Encode(string str) { return !string.IsNullOrEmpty(str) ? WebUtility.UrlEncode(str).Replace("+", "%20") .Replace("*", "%2A") .Replace("%7E", "~") .Replace("!", "%21") .Replace("'","%27") .Replace("(", "%28") .Replace(")", "%29") :str; } }
阿里的URLEncode 有点过期,或者说自定义的,须要咱们特殊处理。spa
附:阿里签名规则.net
Which characters make a URL invalid?
Les codes hexas et unicode des caractères usuels, par Nicolas Hoffmann