类 HttpUtils
- java.lang.Object
-
- com.baidubce.util.HttpUtils
-
public class HttpUtils extends Object
-
-
构造器概要
构造器 构造器 说明 HttpUtils()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static URIappendUri(URI baseUri, String... pathComponents)Append the given path to the given baseUri.static StringgenerateHostHeader(URI uri)Returns a host header according to the specified URI.static StringgetCanonicalQueryString(Map<String,String> parameters, boolean forSignature)static booleanisUsingNonDefaultPort(URI uri)Returns true if the specified URI is using a non-standard port (i.e.static Stringnormalize(String value)Normalize a string for use in BCE web service APIs.static StringnormalizePath(String path)Normalize a string for use in url path.static voidprintRequest(org.apache.http.client.methods.HttpRequestBase request)static voidprintResponse(org.apache.http.client.methods.CloseableHttpResponse response)
-
-
-
方法详细资料
-
normalizePath
public static String normalizePath(String path)
Normalize a string for use in url path. The algorithm is:- Normalize the string
- replace all "%2F" with "/"
- 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:- Convert the string into a UTF-8 byte array.
- 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)
-
-