public class HttpClientUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
HTTP_TIMEOUT |
static java.lang.String |
HTTP_USER_AGENT |
static java.lang.String |
REVISION |
Constructor and Description |
---|
HttpClientUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
executeMethodAndGetContentAsStringOrAsFile(org.apache.commons.httpclient.HttpClient client,
org.apache.commons.httpclient.HttpMethodBase method,
java.io.File file) |
static java.lang.String |
getContent(java.lang.String url)
Retrieves the content of the specified url as a string.
|
static void |
getContent(java.lang.String url,
java.io.File file)
Save the content of the specified url in the given file.
|
static void |
getContent(java.lang.String url,
java.io.File file,
int timeout)
Save the content of the specified url in the given file.
|
static void |
getContent(java.lang.String url,
java.io.File file,
int timeout,
java.lang.String userAgent)
Save the content of the specified url in the given file.
|
static java.lang.String |
getContent(java.lang.String url,
int timeout,
java.lang.String userAgent)
Retrieves the content of the specified url.
|
static java.lang.String |
getContent(java.lang.String url,
java.lang.String userAgent)
Retrieves the content of the specified url.
|
static org.apache.commons.httpclient.HttpClient |
getNewHttpClient(java.lang.String url,
int timeout)
Retrieve a new configured HttpClient instance.
|
static java.lang.String |
postAndGetContent(java.lang.String url,
int timeout,
java.lang.String userAgent,
org.apache.commons.httpclient.NameValuePair[] data)
Post the specified data to the specified url and retrieve the content as a string.
|
static java.lang.String |
postAndGetContent(java.lang.String url,
int timeout,
java.lang.String userAgent,
org.apache.commons.httpclient.NameValuePair[] data,
java.lang.String charset)
Post the specified data to the specified url and retrieve the content as a string.
|
static java.lang.String |
postAndGetContentAsStringOrAsFile(java.lang.String url,
java.io.File file,
int timeout,
java.lang.String userAgent,
org.apache.commons.httpclient.NameValuePair[] data,
java.lang.String charset) |
static void |
setProxyParams(org.apache.commons.httpclient.HttpClient client,
java.lang.String remoteHostName)
Set HttpClient proxy parameters based on Java Properties.
|
static void |
setProxyParamsForUrl(org.apache.commons.httpclient.HttpClient client,
java.lang.String remoteUrl)
Set HttpClient proxy parameters based on Java Properties.
|
static void |
setProxyParamsForUrl(org.apache.commons.httpclient.HttpClient client,
java.net.URL remoteURL)
Set HttpClient proxy parameters based on Java Properties.
|
public static final java.lang.String REVISION
public static int HTTP_TIMEOUT
public static java.lang.String HTTP_USER_AGENT
public static org.apache.commons.httpclient.HttpClient getNewHttpClient(java.lang.String url, int timeout) throws java.net.MalformedURLException
url
- the url that will be accessed with this clienttimeout
- the timeout value to usejava.net.MalformedURLException
- if an error occurred.public static void setProxyParams(org.apache.commons.httpclient.HttpClient client, java.lang.String remoteHostName)
client
- the HttpClient instance of which proxy parametersremoteHostName
- the remote URL for which the HttpClient is being used
it is required in order to be able to apply the rules specified
in the system property "http.nonProxyHosts"public static void setProxyParamsForUrl(org.apache.commons.httpclient.HttpClient client, java.lang.String remoteUrl) throws java.net.MalformedURLException
client
- the HttpClient instance of which proxy parametersremoteUrl
- the remote url for which the HttpClient is being used.
It is required in order to be able to apply the rules specified
in the system property "http.nonProxyHosts"java.net.MalformedURLException
- if an error occurred.public static void setProxyParamsForUrl(org.apache.commons.httpclient.HttpClient client, java.net.URL remoteURL)
client
- the HttpClient instance of which proxy parametersremoteURL
- the remote URL for which the HttpClient is being used.
It is required in order to be able to apply the rules specified
in the system property "http.nonProxyHosts"public static java.lang.String getContent(java.lang.String url) throws org.apache.commons.httpclient.HttpException, java.io.IOException
Warning: The size of the response body is not controlled and may consume a lot of memory.
url
- the url to accessorg.apache.commons.httpclient.HttpException
- if an error occurred.java.io.IOException
- if an error occurred.public static java.lang.String getContent(java.lang.String url, java.lang.String userAgent) throws org.apache.commons.httpclient.HttpException, java.io.IOException
Warning: The size of the response body is not controlled and may consume a lot of memory.
url
- the url to accessuserAgent
- the User-Agentorg.apache.commons.httpclient.HttpException
- if an error occurred.java.io.IOException
- if an error occurred.public static java.lang.String getContent(java.lang.String url, int timeout, java.lang.String userAgent) throws org.apache.commons.httpclient.HttpException, java.io.IOException
Warning: The size of the response body is not controlled and may consume a lot of memory.
url
- the url to accesstimeout
- the time (in milliseconds) to wait for a connection to become available.
Default value is 3000 (3 seconds).
Default value will be used if zero or a negative value is specified.userAgent
- the User-Agentorg.apache.commons.httpclient.HttpException
- if an error occurred.java.io.IOException
- if an error occurred.public static void getContent(java.lang.String url, java.io.File file) throws org.apache.commons.httpclient.HttpException, java.io.IOException
url
- the url to accessfile
- the output fileorg.apache.commons.httpclient.HttpException
- if an error occurred.java.io.IOException
- if an error occurred.public static void getContent(java.lang.String url, java.io.File file, int timeout) throws org.apache.commons.httpclient.HttpException, java.io.IOException
url
- the url to accessfile
- the output filetimeout
- the time (in milliseconds) to wait for a connection to become available.
Default value is 3000 (3 seconds).
Default value will be used if zero or a negative value is specified.org.apache.commons.httpclient.HttpException
- if an error occurred.java.io.IOException
- if an error occurred.public static void getContent(java.lang.String url, java.io.File file, int timeout, java.lang.String userAgent) throws org.apache.commons.httpclient.HttpException, java.io.IOException
url
- the url to accessuserAgent
- the User-Agentfile
- the output filetimeout
- the connection timeoutorg.apache.commons.httpclient.HttpException
- if an error occurred.java.io.IOException
- if an error occurred.public static java.lang.String postAndGetContent(java.lang.String url, int timeout, java.lang.String userAgent, org.apache.commons.httpclient.NameValuePair[] data) throws org.apache.commons.httpclient.HttpException, java.io.IOException
Warning: The size of the response body is not controlled and may consume a lot of memory. Charset encoding used is the default one in HTTP : ISO-8859-1
url
- the url to accesstimeout
- the time (in milliseconds) to wait for a connection to become available.
Default value is 3000 (3 seconds).
Default value will be used if zero or a negative value is specified.userAgent
- the User-Agentdata
- the parameters to be posted to the remote urlorg.apache.commons.httpclient.HttpException
- if an error occurred.java.io.IOException
- if an error occurred.public static java.lang.String postAndGetContent(java.lang.String url, int timeout, java.lang.String userAgent, org.apache.commons.httpclient.NameValuePair[] data, java.lang.String charset) throws org.apache.commons.httpclient.HttpException, java.io.IOException
Warning: The size of the response body is not controlled and may consume a lot of memory.
url
- the url to accesstimeout
- the time (in milliseconds) to wait for a connection to become available.
Default value is 3000 (3 seconds).
Default value will be used if zero or a negative value is specified.userAgent
- the User-Agentdata
- the parameters to be posted to the remote urlcharset
- the charset encoding to use. If null, uses the default one in HTTP : ISO-8859-1org.apache.commons.httpclient.HttpException
- if an error occurred.java.io.IOException
- if an error occurred.public static java.lang.String postAndGetContentAsStringOrAsFile(java.lang.String url, java.io.File file, int timeout, java.lang.String userAgent, org.apache.commons.httpclient.NameValuePair[] data, java.lang.String charset) throws org.apache.commons.httpclient.HttpException, java.io.IOException
org.apache.commons.httpclient.HttpException
java.io.IOException
public static java.lang.String executeMethodAndGetContentAsStringOrAsFile(org.apache.commons.httpclient.HttpClient client, org.apache.commons.httpclient.HttpMethodBase method, java.io.File file) throws org.apache.commons.httpclient.HttpException, java.io.IOException
org.apache.commons.httpclient.HttpException
java.io.IOException
Copyright © 2001-2010 Jalios SA. All Rights Reserved.