public class HttpRequest extends Object
Modifier and Type | Field and Description |
---|---|
static short |
ENCTYPE_APPLICATION_X_WWW_FORM_URLENCODED
enctype constant
|
static short |
ENCTYPE_MULTIPART_FORM_DATA
enctype constant
|
static short |
ENCTYPE_NA
enctype constant
|
static short |
ENCTYPE_TEXT_PLAIN
enctype constant
|
static short |
TYPE_DELETE
HTTP request type constant denoting a DELETE request.
|
static short |
TYPE_GET
HTTP request type constant denoting a GET request.
|
static short |
TYPE_HEAD
HTTP request type constant denoting a HEAD request.
|
static short |
TYPE_POST
HTTP request type constant denoting a POST request.
|
static short |
TYPE_PUT
HTTP request type constant denoting a PUT request.
|
Modifier and Type | Method and Description |
---|---|
void |
addNameValuePair(String name,
String value)
Adds the specified (case sensitive) name and value; the added values should be url-encoded if creating a request of who's enctype is ENCTYPE_APPLICATION_X_WWW_FORM_URLENCODED
|
String |
asUrl()
Returns a url representation of the HttpRequest (with any name value pairs placed in the query string)
|
static String |
enctypeToString(short enctype)
Returns a String representation of the specified enctype constant.
|
Map<String,String> |
getAdditionalHeaders()
Returns the Map of the additional headers for the request.
|
String |
getContent()
Returns the content body associated with a PUT request.
|
short |
getEnctype()
Retrieves the enctype of the form.
|
short |
getMethod()
Returns the request method as a request type constant.
|
MultiMap<String,File> |
getNameFilePairs()
Returns a live MultiMap of name-File pairs, representing the files to be uploaded.
|
MultiMap<String,String> |
getNameValuePairs()
Returns a MultiMap of name-value pairs, where each name can be associated with multiple values.
|
String |
getUrl()
Returns the url to which the HttpRequest is targeted.
|
static HttpRequest |
make(short httpMethod,
String url,
short enctype,
MultiMap<String,String> nameValuePairs,
MultiMap<String,File> nameFilePairs,
String content,
Map<String,String> additionalHeaders)
Creates and returns an HTTP request.
|
static HttpRequest |
makeDELETE(String url)
Creates and returns a DELETE HttpRequest.
|
static HttpRequest |
makeDELETE(String url,
Map<String,String> additionalHeaders)
Creates and returns a DELETE HttpRequest.
|
static HttpRequest |
makeGET(String url)
Creates and returns a GET HttpRequest.
|
static HttpRequest |
makeGET(String url,
MultiMap<String,String> nameValuePairs,
Map<String,String> additionalHeaders)
Creates and returns a GET HttpRequest.
|
static HttpRequest |
makeHEAD(String url)
Creates and returns a HEAD HttpRequest.
|
static HttpRequest |
makeHEAD(String url,
Map<String,String> additionalHeaders)
Creates and returns a HEAD HttpRequest.
|
static HttpRequest |
makePOST(String url,
MultiMap<String,String> nameValuePairs)
Creates and returns a POST HttpRequest.
|
static HttpRequest |
makePOST(String url,
short enctype,
MultiMap<String,String> nameValuePairs,
MultiMap<String,File> nameFilePairs,
Map<String,String> additionalHeaders)
Creates and returns a POST HttpRequest.
|
static HttpRequest |
makePUT(String url,
String content)
Creates and returns a PUT HttpRequest.
|
static HttpRequest |
makePUT(String url,
String content,
Map<String,String> additionalHeaders)
Creates and returns a PUT HttpRequest.
|
static String |
methodToString(short method)
Returns a String representation of the specified method constant.
|
void |
removeNameValuePairs(String name)
Removes all values associated with the specified (case insensitive) name from the collection of name-value pairs.
|
void |
setEnctype(short enctype)
Sets the enctype to the specified enctype constant.
|
void |
setNameValuePair(String name,
String value)
Adds the specified name and value, removing any other values associated with the specified name, irrespective of the case of the name; the added values should be url-encoded if creating a request of who's enctype is ENCTYPE_APPLICATION_X_WWW_FORM_URLENCODED.
|
String |
toString()
Returns a String representation of the HttpRequest.
|
public static final short ENCTYPE_MULTIPART_FORM_DATA
public static final short ENCTYPE_APPLICATION_X_WWW_FORM_URLENCODED
public static final short ENCTYPE_TEXT_PLAIN
public static final short ENCTYPE_NA
public static final short TYPE_POST
public static final short TYPE_GET
public static final short TYPE_HEAD
public static final short TYPE_DELETE
public static final short TYPE_PUT
public static HttpRequest make(short httpMethod, String url, short enctype, MultiMap<String,String> nameValuePairs, MultiMap<String,File> nameFilePairs, String content, Map<String,String> additionalHeaders)
httpMethod
- an httpRequest method type constant (eg, HttpRequest.TYPE_GET).url
- the fully qualified url to which the request will be sent (the url may contain a query String, however if the nameValuePairs parameter is passed in, those values with be used to construct the queryString instead).enctype
- an enctype constant (GET requests and most POST requests should be ENCTYPE_APPLICATION_X_WWW_FORM_URLENCODED; POST requests that involve file uploads should be ENCTYPE_MULTIPART_FORM_DATA; HEAD, DELETE and PUT requests should be ENCTYPE_NA)nameValuePairs
- a MultiMap of name-value pairs (ie form field data) or null; each name (key) can be associated with one or more values; the values should be url-encoded if creating a request of who's enctype is ENCTYPE_APPLICATION_X_WWW_FORM_URLENCODEDnameFilePairs
- a MultiMap of name-file pairs to be uploaded or null.additionalHeaders
- a Map of header names and header values for this request (which are added-to or override the auto-managed headers [eg cookies, referer, etc] as well as the headers specified in UserAgent.settings.defaultRequestHeaders); can be nullpublic static HttpRequest makeGET(String url, MultiMap<String,String> nameValuePairs, Map<String,String> additionalHeaders)
url
- the fully qualified url to which the request will be sent (the url may contain a query String, however if the nameValuePairs parameter is passed in, those values with be used to construct the queryString instead).nameValuePairs
- a MultiMap of name-value pairs (ie form field data) or null; each name (key) can be associated with one or more values; the values should be url-encoded.additionalHeaders
- a Map of header names and header values for this request (which are added-to or override the auto-managed headers [eg cookies, referer, etc] as well as the headers specified in UserAgent.settings.defaultRequestHeaders); can be nullpublic static HttpRequest makeGET(String url)
url
- the fully qualified url to which the request will be sent (the url may contain a query String).public static HttpRequest makePOST(String url, short enctype, MultiMap<String,String> nameValuePairs, MultiMap<String,File> nameFilePairs, Map<String,String> additionalHeaders)
url
- the fully qualified url to which the request will be sent.enctype
- an enctype constant of HttpRequest (POST requests that involve file uploads must be ENCTYPE_MULTIPART_FORM_DATA, otherwise they may be ENCTYPE_APPLICATION_X_WWW_FORM_URLENCODED)nameValuePairs
- a MultiMap of name-value pairs (ie form field data) or null; each name (key) can be associated with one or more values; the name and values should be url-encoded if the encyType parameter is ENCTYPE_APPLICATION_X_WWW_FORM_URLENCODEDnameFilePairs
- a MultiMap of name-file pairs to be uploaded or null.additionalHeaders
- a Map of header names and header values for this request (which are added-to or override the auto-managed headers [eg cookies, referer, etc] as well as the headers specified in UserAgent.settings.defaultRequestHeaders); can be nullpublic static HttpRequest makePOST(String url, MultiMap<String,String> nameValuePairs)
url
- the fully qualified url to which the request will be sent.nameValuePairs
- a MultiMap of name-value pairs (ie form field data) or null; each name (key) can be associated with one or more values; the names and values should be url-encoded.public static HttpRequest makePUT(String url, String content, Map<String,String> additionalHeaders)
url
- the fully qualified url to which the request will be sent.content
- the content body or null.additionalHeaders
- a Map of header names and header values for this request (which are added-to or override the auto-managed headers [eg cookies, referer, etc] as well as the headers specified in UserAgent.settings.defaultRequestHeaders); can be nullpublic static HttpRequest makePUT(String url, String content)
url
- the fully qualified url to which the request will be sent.content
- the content body or null.public static HttpRequest makeDELETE(String url, Map<String,String> additionalHeaders)
url
- the fully qualified url to which the request will be sent.additionalHeaders
- a Map of header names and header values for this request (which are added-to or override the auto-managed headers [eg cookies, referer, etc] as well as the headers specified in UserAgent.settings.defaultRequestHeaders); can be nullpublic static HttpRequest makeDELETE(String url)
url
- the fully qualified url to which the request will be sent.public static HttpRequest makeHEAD(String url, Map<String,String> additionalHeaders)
url
- the fully qualified url to which the request will be sent.additionalHeaders
- a Map of header names and header values for this request (which are added-to or override the auto-managed headers [eg cookies, referer, etc] as well as the headers specified in UserAgent.settings.defaultRequestHeaders); can be nullpublic static HttpRequest makeHEAD(String url)
url
- the fully qualified url to which the request will be sent.public Map<String,String> getAdditionalHeaders()
public String getContent()
public short getMethod()
public String getUrl()
public void setEnctype(short enctype)
public short getEnctype()
public MultiMap<String,File> getNameFilePairs()
public void setNameValuePair(String name, String value)
value
- the url-encoded value, which should be encoded (eg using java.net.URLEncoder.encode).public void addNameValuePair(String name, String value)
value
- the url-encoded value, which should be encoded (eg using java.net.URLEncoder.encode).public void removeNameValuePairs(String name)
public MultiMap<String,String> getNameValuePairs()
public static String methodToString(short method)
public static String enctypeToString(short enctype)
public String asUrl()