Class SimpleHttpClient
- Object
-
- AbstractHttpClient
-
- SimpleHttpClient
-
- All Implemented Interfaces:
HTTPBehavior,HTTPClient,HTTPProxy
public class SimpleHttpClient extends AbstractHttpClient implements HTTPProxy
A simpleHTTPClientthat creates a newHTTP connectionfor each request.- Author:
- groldan
-
-
Field Summary
-
Fields inherited from class AbstractHttpClient
connectTimeout, extraParams, password, readTimeout, tryGzip, user
-
-
Constructor Summary
Constructors Constructor Description SimpleHttpClient()A SimpleHttpClient should be initiated by a call to HTTPFactoryFinder.getHttpClientFactory().getClient();
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HTTPResponseget(URL url)Executes an HTTP GET request against the provided URL and returns the server response.HTTPResponseget(URL url, Map<String,String> headers)Executes an HTTP GET request against the provided URL and returns the server response.HTTPResponsepost(URL url, InputStream content, String contentType)Executes an HTTP POST request against the provided URL, sending the contents ofpostContentas the POST method body and setting the Content-Type request header topostContentTypeif given, and returns the server response.HTTPResponsepost(URL url, InputStream postContent, String postContentType, Map<String,String> headers)Executes an HTTP POST request against the provided URL, sending the contents ofpostContentas the POST method body and setting the Content-Type request header topostContentTypeif given, and returns the server response.-
Methods inherited from class AbstractHttpClient
appendURL, createFileResponse, getConnectTimeout, getExtraParams, getPassword, getReadTimeout, getUser, isFile, isTryGzip, setConnectTimeout, setExtraParams, setPassword, setReadTimeout, setTryGzip, setUser
-
-
-
-
Method Detail
-
get
public HTTPResponse get(URL url) throws IOException
Description copied from interface:HTTPClientExecutes an HTTP GET request against the provided URL and returns the server response.If an HTTP authentication
userandpasswordis set, the appropriate authentication HTTP header will be sent with the request.If a
connection timeoutis set, the http connection will be set to respect that timeout.If a
read timeoutis set, the http connection will be set to respect it.- Specified by:
getin interfaceHTTPClient- Parameters:
url- the URL to retrieve- Returns:
- an
HTTPResponseencapsulating the response to the HTTP GET request - Throws:
IOException- See Also:
HTTPClient.get(java.net.URL)
-
get
public HTTPResponse get(URL url, Map<String,String> headers) throws IOException
Description copied from interface:HTTPClientExecutes an HTTP GET request against the provided URL and returns the server response.If an HTTP authentication
userandpasswordis set, the appropriate authentication HTTP header will be sent with the request.If a
connection timeoutis set, the http connection will be set to respect that timeout.If a
read timeoutis set, the http connection will be set to respect it.header parameter contains additional headers to add to the request.
- Specified by:
getin interfaceHTTPClient- Parameters:
url- the URL to retrieveheaders- a list of custom headers to add to the request.- Returns:
- an
HTTPResponseencapsulating the response to the HTTP GET request - Throws:
IOException- See Also:
HTTPClient.get(URL, Map)
-
post
public HTTPResponse post(URL url, InputStream content, String contentType) throws IOException
Description copied from interface:HTTPClientExecutes an HTTP POST request against the provided URL, sending the contents ofpostContentas the POST method body and setting the Content-Type request header topostContentTypeif given, and returns the server response.If an HTTP authentication
userandpasswordis set, the appropriate authentication HTTP header will be sent with the request.If a
connection timeoutis set, the http connection will be set to respect that timeout.If a
read timeoutis set, the http connection will be set to respect it.- Specified by:
postin interfaceHTTPClient- Specified by:
postin classAbstractHttpClient- Parameters:
url- the URL against which to execute the POST requestcontent- an input stream with the contents of the POST bodycontentType- the MIME type of the contents sent as the request POST body, can benull- Returns:
- the
HTTPResponseencapsulating the response to the HTTP POST request - Throws:
IOException- See Also:
HTTPClient.post(URL, InputStream, String, Map)
-
post
public HTTPResponse post(URL url, InputStream postContent, String postContentType, Map<String,String> headers) throws IOException
Description copied from interface:HTTPClientExecutes an HTTP POST request against the provided URL, sending the contents ofpostContentas the POST method body and setting the Content-Type request header topostContentTypeif given, and returns the server response.If an HTTP authentication
userandpasswordis set, the appropriate authentication HTTP header will be sent with the request.If a
connection timeoutis set, the http connection will be set to respect that timeout.If a
read timeoutis set, the http connection will be set to respect it.header parameter contains additional headers to add to the request.
- Specified by:
postin interfaceHTTPClient- Parameters:
url- the URL against which to execute the POST requestpostContent- an input stream with the contents of the POST bodypostContentType- the MIME type of the contents sent as the request POST body, can benullheaders- a list of custom headers to add to the request.- Returns:
- the
HTTPResponseencapsulating the response to the HTTP POST request - Throws:
IOException- See Also:
HTTPClient.post(URL, InputStream, String)
-
-