类 HttpUtils


  • public class HttpUtils
    extends Object
    • 构造器详细资料

      • HttpUtils

        public HttpUtils()
    • 方法详细资料

      • normalizePath

        public static String normalizePath​(String path)
        Normalize a string for use in url path. The algorithm is:

        1. Normalize the string
        2. replace all "%2F" with "/"
        3. replace all "//" with "/%2F"

        Bos object key can contain arbitrary characters, which may result double slash in the url path. Apache http client will replace "//" in the path with a single '/', which makes the object key incorrect. Thus we replace "//" with "/%2F" here.

        参数:
        path - the path string to normalize.
        返回:
        the normalized path string.
        另请参阅:
        normalize(String)
      • normalize

        public static String normalize​(String value)
        Normalize a string for use in BCE web service APIs. The normalization algorithm is:

        1. Convert the string into a UTF-8 byte array.
        2. Encode all octets into percent-encoding, except all URI unreserved characters per the RFC 3986.

        All letters used in the percent-encoding are in uppercase.

        参数:
        value - the string to normalize.
        返回:
        the normalized string.
      • generateHostHeader

        public static String generateHostHeader​(URI uri)
        Returns a host header according to the specified URI. The host header is generated with the same logic used by apache http client, that is, append the port to hostname only if it is not the default port.
        参数:
        uri - the URI
        返回:
        a host header according to the specified URI.
      • isUsingNonDefaultPort

        public static boolean isUsingNonDefaultPort​(URI uri)
        Returns true if the specified URI is using a non-standard port (i.e. any port other than 80 for HTTP URIs or any port other than 443 for HTTPS URIs).
        参数:
        uri - the URI
        返回:
        True if the specified URI is using a non-standard port, otherwise false.
      • getCanonicalQueryString

        public static String getCanonicalQueryString​(Map<String,​String> parameters,
                                                     boolean forSignature)
      • appendUri

        public static URI appendUri​(URI baseUri,
                                    String... pathComponents)
        Append the given path to the given baseUri.

        This method will encode the given path but not the given baseUri.

        参数:
        baseUri -
        pathComponents -
      • printRequest

        public static void printRequest​(org.apache.http.client.methods.HttpRequestBase request)
      • printResponse

        public static void printResponse​(org.apache.http.client.methods.CloseableHttpResponse response)