|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface HttpRequest
An object representing an HTTP request to be made in the future. The actual request is not made until execute()
is called.
Method Summary | |
---|---|
void |
addFileUpload(java.lang.String name,
DataFile dataFile)
Add the contents of a file to the request, which will make this a multipart request and transmit the file contents as a multipart part. |
void |
addFileUpload(java.lang.String name,
DataFile dataFile,
java.lang.String contentType)
Add the contents of a file to the request, which will make this a multipart request and transmit the file contents as a multipart part. |
void |
addRequestHeader(java.lang.String key,
java.lang.String value)
Adds or sets a HTTP header with the supplied value. |
void |
addRequestHeaders(NativeObject paramsNO)
Adds a set of HTTP headers to the HTTP request. |
void |
addRequestParameter(java.lang.String key,
java.lang.String value)
Adds an HTTP request parameter to be included with the HTTP POST request. |
void |
addRequestParameters(NativeObject paramsNO)
Adds a set of HTTP parameters to the HTTP request. |
void |
appendRequestHeader(java.lang.String key,
java.lang.String value)
Adds a HTTP header with the supplied key and value. |
HttpResponse |
execute()
Executes this HTTP request. |
java.lang.String |
getUrl()
Get the URL. |
boolean |
hasHeader(java.lang.String header)
Check if the request has a header set |
void |
makeMultiPart()
Change the request into a multipart request, so that each named parameter is treated as separate part. |
void |
removeHeader(java.lang.String header)
Remove an existing header from the request |
void |
setRequestBody(java.lang.Object body)
Sets the raw content of the HTTP POST (or PUT) body. |
void |
setRequestBody(java.lang.Object body,
java.lang.String contentType,
java.lang.String charSet)
Convenience function for setting the body of the HTTP and also setting the Content-Type header. |
void |
setRequestBodyAsBase64EncodedBytes(java.lang.String bodyBase64Encoded)
Deprecated. Consider using DataFile and/or Bytes along with setRequestBody(Object) |
void |
setVerificationText(java.lang.String verificationText)
Instructs the HTTP request to look for this string of content against the response content. |
Method Detail |
---|
void addRequestHeader(java.lang.String key, java.lang.String value)
If the key already exists this will overwrite it.
key
- the HTTP header key.value
- the HTTP header value.void appendRequestHeader(java.lang.String key, java.lang.String value)
If the key already exists, a new value is added.
For example the following adds two 'blah' headers.
var req = c.newGet("http://www.example.com"); req.appendRequestHeader("blah", "foo"); req.appendRequestHeader("blah", "bar"); var response = req.execute();
key
- the HTTP header key.value
- the HTTP header value.void addRequestHeaders(NativeObject paramsNO)
post.addRequestHeaders({ header_one: 'some value', header_two: ['foo', 'bar'] });
paramsNO
- the JavaScript map of headers used when issuing the HTTP request.void removeHeader(java.lang.String header)
header
- the header name to removeboolean hasHeader(java.lang.String header)
header
- the header name to remove
java.lang.String getUrl()
void setVerificationText(java.lang.String verificationText)
HttpResponse.isContentMatched()
.
verificationText
- the text to check against the returned content.void addRequestParameter(java.lang.String key, java.lang.String value)
key
- the HTTP parameter key.value
- the HTTP parameter value.void addRequestParameters(NativeObject paramsNO)
post.addRequestParameters({ 'name1': 'value1', 'name2': 'value2', 'name3': ['value3', 'value4'] });
paramsNO
- the JavaScript map of parameters used when issuing an HTTP POST.void setRequestBody(java.lang.Object body, java.lang.String contentType, java.lang.String charSet)
setRequestBody(Object)
for more info.
body
- the body of the HTTP request.contentType
- the content type of the body.charSet
- the character set encoding (eg: UTF-8).void setRequestBody(java.lang.Object body)
DataFile
, or a set
of Bytes
.
If you are uploading a string, it is assumed to be in UTF-8 character encoding.
If you are uploading a DataFile
, please note that this is different than
addFileUpload(String, DataFile)
, which simulates what a browser does for file uploads by making the request
a multi-part request.
If you are uploading some Bytes
, the most common use case is that those bytes were obtained from
Utils.gzip(Object)
.
Note that while this does automatically set the Content-Length request header, it does not (currently) handle
anything related to content types or content encoding, so you must set those headers yourself if they are needed.
You may also consider using setRequestBody(Object, String, String)
as a shortcut to setting the body and
setting the content type header.
body
- the body of the HTTP request.void setRequestBodyAsBase64EncodedBytes(java.lang.String bodyBase64Encoded)
DataFile
and/or Bytes
along with setRequestBody(Object)
bodyBase64Encoded
- the body of the HTTP request in bytes encoded as a base64 string.HttpResponse execute()
void addFileUpload(java.lang.String name, DataFile dataFile)
name
- the request part namedataFile
- the file to use as the content body. You can get a handle to an uploaded file using test.getFile(String)void addFileUpload(java.lang.String name, DataFile dataFile, java.lang.String contentType)
name
- the request part namedataFile
- the file to use as the content body. You can get a handle to an uploaded file using test.getFile(String)contentType
- the Content-Type of the file being uploadedvoid makeMultiPart()
Multipart requests are made automatically after calling addFileUpload()
so there is
no need to call this function in that case.
|
© 2023 Vercara, LLC. All Rights Reserved. | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |