public class WebRequest extends Object implements Serializable
Modifier and Type | Class and Description |
---|---|
static class |
WebRequest.HttpHint |
Constructor and Description |
---|
WebRequest(URL url)
Instantiates a
WebRequest for the specified URL. |
WebRequest(URL url,
Charset charset,
URL refererUrl)
Instantiates a
WebRequest for the specified URL. |
WebRequest(URL url,
HttpMethod submitMethod)
Instantiates a
WebRequest for the specified URL using the specified HTTP submit method. |
WebRequest(URL url,
String acceptHeader,
String acceptEncodingHeader)
Instantiates a
WebRequest for the specified URL. |
Modifier and Type | Method and Description |
---|---|
void |
addHint(WebRequest.HttpHint hint) |
String |
getAdditionalHeader(String name)
Returns the header value associated with this name.
|
Map<String,String> |
getAdditionalHeaders()
Returns the additional HTTP headers to use.
|
Charset |
getCharset()
Returns the character set to use to perform the request.
|
org.apache.http.auth.Credentials |
getCredentials()
Returns the credentials to use.
|
Charset |
getDefaultResponseContentCharset() |
FormEncodingType |
getEncodingType()
Returns the form encoding type to use.
|
HttpMethod |
getHttpMethod()
Returns the HTTP submit method to use.
|
List<NameValuePair> |
getParameters()
Retrieves the request parameters used.
|
String |
getProxyHost()
Returns the proxy host to use.
|
int |
getProxyPort()
Returns the proxy port to use.
|
String |
getProxyScheme()
Returns the proxy scheme to use.
|
String |
getRequestBody()
Returns the body content to be submitted if this is a
POST request. |
List<NameValuePair> |
getRequestParameters()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
int |
getTimeout() |
URL |
getUrl()
Returns the target URL.
|
org.apache.http.auth.Credentials |
getUrlCredentials()
Returns the credentials to use.
|
boolean |
hasHint(WebRequest.HttpHint hint) |
boolean |
isAdditionalHeader(String name)
Returns whether the specified header name is already included in the additional HTTP headers.
|
boolean |
isSocksProxy()
Returns whether SOCKS proxy or not.
|
static WebRequest |
newAboutBlankRequest() |
void |
removeAdditionalHeader(String name)
Removed the specified name/value pair from the additional HTTP headers.
|
void |
setAdditionalHeader(String name,
String value)
Sets the specified name/value pair in the additional HTTP headers.
|
void |
setAdditionalHeaders(Map<String,String> additionalHeaders)
Sets the additional HTTP headers to use.
|
void |
setCharset(Charset charset)
Sets the character set to use to perform the request.
|
void |
setCredentials(org.apache.http.auth.Credentials credentials)
Sets the credentials to use.
|
void |
setDefaultResponseContentCharset(Charset defaultResponseContentCharset)
Sets the default character set to use for the response when it does not specify one.
|
void |
setEncodingType(FormEncodingType encodingType)
Sets the form encoding type to use.
|
void |
setHttpMethod(HttpMethod submitMethod)
Sets the HTTP submit method to use.
|
void |
setProxyHost(String proxyHost)
Sets the proxy host to use.
|
void |
setProxyPort(int proxyPort)
Sets the proxy port to use.
|
void |
setProxyScheme(String proxyScheme)
Sets the proxy scheme to use.
|
void |
setRefererHeader(URL url)
Sets the referer HTTP header - only if the provided url is valid.
|
void |
setRefererlHeader(URL url)
Deprecated.
as of version 4.5.0; use
setRefererHeader(URL) instead |
void |
setRequestBody(String requestBody)
Sets the body content to be submitted if this is a
POST , PUT or PATCH request. |
void |
setRequestParameters(List<NameValuePair> requestParameters)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
void |
setSocksProxy(boolean isSocksProxy)
Sets whether SOCKS proxy or not.
|
void |
setTimeout(int timeout)
Sets the timeout to use.
|
void |
setUrl(URL url)
Sets the target URL.
|
String |
toString()
Returns a string representation of this object.
|
public WebRequest(URL url, String acceptHeader, String acceptEncodingHeader)
WebRequest
for the specified URL.url
- the target URLacceptHeader
- the accept header to useacceptEncodingHeader
- the accept encoding header to usepublic WebRequest(URL url, Charset charset, URL refererUrl)
WebRequest
for the specified URL.url
- the target URLcharset
- the charset to userefererUrl
- the url be used by the referer headerpublic WebRequest(URL url)
WebRequest
for the specified URL.url
- the target URLpublic WebRequest(URL url, HttpMethod submitMethod)
WebRequest
for the specified URL using the specified HTTP submit method.url
- the target URLsubmitMethod
- the HTTP submit method to usepublic static WebRequest newAboutBlankRequest()
public URL getUrl()
public void setUrl(URL url)
url
- the target URLpublic String getProxyHost()
public void setProxyHost(String proxyHost)
proxyHost
- the proxy host to usepublic int getProxyPort()
public void setProxyPort(int proxyPort)
proxyPort
- the proxy port to usepublic String getProxyScheme()
public void setProxyScheme(String proxyScheme)
proxyScheme
- the proxy scheme to usepublic boolean isSocksProxy()
public void setSocksProxy(boolean isSocksProxy)
isSocksProxy
- whether SOCKS proxy or notpublic int getTimeout()
public void setTimeout(int timeout)
timeout
- the timeout to usepublic FormEncodingType getEncodingType()
public void setEncodingType(FormEncodingType encodingType)
encodingType
- the form encoding type to usepublic List<NameValuePair> getParameters()
Retrieves the request parameters used. Similar to the servlet api function
getParameterMap() this works depending on the request type and collects the
url parameters and the body stuff.
The value is also normalized - null is converted to an empty string.
In contrast to the servlet api this creates a separate KeyValuePair for every
parameter. This means that pairs with the same name can be part of the list. The
servlet api will return a string[] as value for the key in this case.
Additionally this method includes also the uploaded files for multipart post
requests.
public List<NameValuePair> getRequestParameters()
URL
. Should not be used in
combination with the request body
.public void setRequestParameters(List<NameValuePair> requestParameters) throws RuntimeException
URL
. Should not be used in combination
with the request body
.requestParameters
- the request parameters to useRuntimeException
- if the request body has already been setpublic String getRequestBody()
POST
request. Ignored for all other request
types. Should not be used in combination with request parameters
.POST
requestpublic void setRequestBody(String requestBody) throws RuntimeException
POST
, PUT
or PATCH
request.
Other request types result in RuntimeException
.
Should not be used in combination with request parameters
.requestBody
- the body content to be submitted if this is a POST
, PUT
or PATCH
requestRuntimeException
- if the request parameters have already been set
or this is not a POST
, PUT
or PATCH
request.public HttpMethod getHttpMethod()
public void setHttpMethod(HttpMethod submitMethod)
submitMethod
- the HTTP submit method to usepublic Map<String,String> getAdditionalHeaders()
public void setAdditionalHeaders(Map<String,String> additionalHeaders)
additionalHeaders
- the additional HTTP headers to usepublic boolean isAdditionalHeader(String name)
name
- the name of the additional HTTP headerpublic String getAdditionalHeader(String name)
name
- the name of the additional HTTP headerpublic void setRefererHeader(URL url)
url
- the url for the referer HTTP header@Deprecated public void setRefererlHeader(URL url)
setRefererHeader(URL)
insteadurl
- the url for the referer HTTP headerpublic void setAdditionalHeader(String name, String value)
name
- the name of the additional HTTP headervalue
- the value of the additional HTTP headerpublic void removeAdditionalHeader(String name)
name
- the name of the additional HTTP headerpublic org.apache.http.auth.Credentials getUrlCredentials()
public org.apache.http.auth.Credentials getCredentials()
public void setCredentials(org.apache.http.auth.Credentials credentials)
credentials
- the credentials to usepublic Charset getCharset()
public void setCharset(Charset charset)
StandardCharsets.ISO_8859_1
.charset
- the character set to use to perform the requestpublic Charset getDefaultResponseContentCharset()
public void setDefaultResponseContentCharset(Charset defaultResponseContentCharset)
Unless set, the default is StandardCharsets.UTF_8
.
defaultResponseContentCharset
- the default character set of the responsepublic boolean hasHint(WebRequest.HttpHint hint)
public void addHint(WebRequest.HttpHint hint)
Copyright © 2002–2024 Gargoyle Software Inc.. All rights reserved.