Class HttpRequest
HttpRequest
with HttpMethod
, URL
,
HttpHeader
and request body.-
Constructor Summary
ConstructorDescriptionHttpRequest
(HttpMethod httpMethod, String url) Create a new HttpRequest instance.HttpRequest
(HttpMethod httpMethod, URL url) Create a new HttpRequest instance.HttpRequest
(HttpMethod httpMethod, URL url, HttpHeaders headers) Create a new HttpRequest instance.HttpRequest
(HttpMethod httpMethod, URL url, HttpHeaders headers, BinaryData body) Create a new HttpRequest instance.HttpRequest
(HttpMethod httpMethod, URL url, HttpHeaders headers, Flux<ByteBuffer> body) Create a new HttpRequest instance. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Creates a copy of the request.getBody()
Get the request content.Get the request content.Get the request headers.Get the request method.getUrl()
Get the target address.setBody
(byte[] content) Set the request content.setBody
(BinaryData content) Set request content.Set the request content.setBody
(Flux<ByteBuffer> content) Set request content.setHeader
(HttpHeaderName headerName, String value) Set a request header, replacing any existing value.Deprecated.setHeaders
(HttpHeaders headers) Set the request headers.setHttpMethod
(HttpMethod httpMethod) Set the request method.Set the target address to send the request to.Set the target address to send the request to.
-
Constructor Details
-
HttpRequest
Create a new HttpRequest instance.- Parameters:
httpMethod
- the HTTP request methodurl
- the target address to send the request to
-
HttpRequest
Create a new HttpRequest instance.- Parameters:
httpMethod
- the HTTP request methodurl
- the target address to send the request to- Throws:
IllegalArgumentException
- ifurl
is null or it cannot be parsed into a valid URL.
-
HttpRequest
Create a new HttpRequest instance.- Parameters:
httpMethod
- the HTTP request methodurl
- the target address to send the request toheaders
- the HTTP headers to use with this request
-
HttpRequest
Create a new HttpRequest instance.- Parameters:
httpMethod
- the HTTP request methodurl
- the target address to send the request toheaders
- the HTTP headers to use with this requestbody
- the request content
-
HttpRequest
Create a new HttpRequest instance.- Parameters:
httpMethod
- the HTTP request methodurl
- the target address to send the request toheaders
- the HTTP headers to use with this requestbody
- the request content
-
-
Method Details
-
getHttpMethod
Get the request method.- Returns:
- the request method
-
setHttpMethod
Set the request method.- Parameters:
httpMethod
- the request method- Returns:
- this HttpRequest
-
getUrl
Get the target address.- Returns:
- the target address
-
setUrl
Set the target address to send the request to.- Parameters:
url
- target address asURL
- Returns:
- this HttpRequest
-
setUrl
Set the target address to send the request to.- Parameters:
url
- target address as a String- Returns:
- this HttpRequest
- Throws:
IllegalArgumentException
- ifurl
is null or it cannot be parsed into a valid URL.
-
getHeaders
Get the request headers.- Returns:
- headers to be sent
-
setHeaders
Set the request headers.- Parameters:
headers
- the set of headers- Returns:
- this HttpRequest
-
setHeader
Deprecated.UsesetHeader(HttpHeaderName, String)
instead as is offers better performance.Set a request header, replacing any existing value. A null forvalue
will remove the header if one with matching name exists.- Parameters:
name
- the header namevalue
- the header value- Returns:
- this HttpRequest
-
setHeader
Set a request header, replacing any existing value. A null forvalue
will remove the header if one with matching name exists.- Parameters:
headerName
- the header namevalue
- the header value- Returns:
- this HttpRequest
-
getBody
Get the request content.- Returns:
- the content to be sent
-
getBodyAsBinaryData
Get the request content.- Returns:
- the content to be sent
-
setBody
Set the request content.The Content-Length header will be set based on the given content's length.
- Parameters:
content
- the request content- Returns:
- this HttpRequest
-
setBody
Set the request content.The Content-Length header will be set based on the given content's length.
- Parameters:
content
- the request content- Returns:
- this HttpRequest
-
setBody
Set request content.Caller must set the Content-Length header to indicate the length of the content, or use Transfer-Encoding: chunked.
- Parameters:
content
- the request content- Returns:
- this HttpRequest
-
setBody
Set request content.If provided content has known length, i.e.
BinaryData.getLength()
returns non-null then Content-Length header is updated. Otherwise, if provided content has unknown length, i.e.BinaryData.getLength()
returns null then the caller must set the Content-Length header to indicate the length of the content, or use Transfer-Encoding: chunked.- Parameters:
content
- the request content- Returns:
- this HttpRequest
-
copy
Creates a copy of the request.The main purpose of this is so that this HttpRequest can be changed and the resulting HttpRequest can be a backup. This means that the cloned HttpHeaders and body must not be able to change from side effects of this HttpRequest.
- Returns:
- a new HTTP request instance with cloned instances of all mutable properties.
-
setHeader(HttpHeaderName, String)
instead as is offers better performance.