Package org.seppiko.commons.utils.http
Class HttpClientUtil
java.lang.Object
org.seppiko.commons.utils.http.HttpClientUtil
public class HttpClientUtil
extends java.lang.Object
Http Client Util with java.net.http
- Author:
- Leonard Woo
-
Constructor Summary
Constructors Constructor Description HttpClientUtil() -
Method Summary
Modifier and Type Method Description static java.net.http.HttpRequestgetRequest(java.lang.String url, HttpMethod method, int timeout, java.util.LinkedHashMap<java.lang.String,java.util.ArrayList<java.lang.String>> headers, byte[] requestBody)Get Request object with byte arraystatic java.net.http.HttpRequestgetRequest(java.lang.String url, HttpMethod method, int timeout, java.util.LinkedHashMap<java.lang.String,java.util.ArrayList<java.lang.String>> headers, java.io.InputStream requestBody)Get Request object with inputstreamstatic java.net.http.HttpRequestgetRequest(java.lang.String url, HttpMethod method, int timeout, java.util.LinkedHashMap<java.lang.String,java.util.ArrayList<java.lang.String>> headers, java.lang.String requestBody)Get Request object with Stringstatic java.net.http.HttpResponse<byte[]>getResponseByteArray(java.net.http.HttpRequest req, java.net.InetSocketAddress proxy)Get Response with byte array bodystatic java.net.http.HttpResponse<java.io.InputStream>getResponseInputStream(java.net.http.HttpRequest req, java.net.InetSocketAddress proxy)Get Response with inputstream bodystatic java.net.http.HttpResponse<java.lang.String>getResponseString(java.net.http.HttpRequest req, java.net.InetSocketAddress proxy)Get Response with String bodyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
HttpClientUtil
public HttpClientUtil()
-
-
Method Details
-
getRequest
public static java.net.http.HttpRequest getRequest(java.lang.String url, HttpMethod method, int timeout, java.util.LinkedHashMap<java.lang.String,java.util.ArrayList<java.lang.String>> headers, java.lang.String requestBody) throws java.net.URISyntaxExceptionGet Request object with String- Parameters:
url- URLmethod- seeHttpMethodtimeout- Timeoutheaders- HeadersrequestBody- Request body string- Returns:
- HttpRequest object
- Throws:
java.net.URISyntaxException- URL is an illegal address
-
getRequest
public static java.net.http.HttpRequest getRequest(java.lang.String url, HttpMethod method, int timeout, java.util.LinkedHashMap<java.lang.String,java.util.ArrayList<java.lang.String>> headers, java.io.InputStream requestBody) throws java.net.URISyntaxExceptionGet Request object with inputstream- Parameters:
url- URLmethod- seeHttpMethodtimeout- Timeoutheaders- HeadersrequestBody- Request body inputstream- Returns:
- HttpRequest object
- Throws:
java.net.URISyntaxException- URL is an illegal address
-
getRequest
public static java.net.http.HttpRequest getRequest(java.lang.String url, HttpMethod method, int timeout, java.util.LinkedHashMap<java.lang.String,java.util.ArrayList<java.lang.String>> headers, byte[] requestBody) throws java.net.URISyntaxExceptionGet Request object with byte array- Parameters:
url- URLmethod- seeHttpMethodtimeout- Timeoutheaders- HeadersrequestBody- Request body byte array- Returns:
- HttpRequest object
- Throws:
java.net.URISyntaxException- URL is an illegal address
-
getResponseString
public static java.net.http.HttpResponse<java.lang.String> getResponseString(java.net.http.HttpRequest req, java.net.InetSocketAddress proxy) throws HttpClientExceptionGet Response with String body- Parameters:
req- HttpRequest objectproxy- Not null is enable proxy- Returns:
- HttpResponse object, if NULL has failed
- Throws:
HttpClientException- get response exception
-
getResponseByteArray
public static java.net.http.HttpResponse<byte[]> getResponseByteArray(java.net.http.HttpRequest req, java.net.InetSocketAddress proxy) throws HttpClientExceptionGet Response with byte array body- Parameters:
req- HttpRequest objectproxy- Not null is enable proxy- Returns:
- HttpResponse object, if NULL has failed
- Throws:
HttpClientException- get response exception
-
getResponseInputStream
public static java.net.http.HttpResponse<java.io.InputStream> getResponseInputStream(java.net.http.HttpRequest req, java.net.InetSocketAddress proxy) throws HttpClientExceptionGet Response with inputstream body- Parameters:
req- HttpRequest objectproxy- Not null is enable proxy- Returns:
- HttpResponse object, if NULL has failed
- Throws:
HttpClientException- get response exception
-