HttpRequest Class
- java.
lang. Object - com.
azure. core. http. HttpRequest
- com.
public class HttpRequest
Represents an outgoing HTTP request.
This class encapsulates an HTTP request, including the HTTP method, URL, headers, and body. It provides methods to set and get these properties.
This class is useful when you want to create an HTTP request to send to a server. For example, you can use it to create a GET request to retrieve a resource, a POST request to create a resource, a PUT request to update a resource, or a DELETE request to delete a resource.
Note: This class provides a copy() method to create a copy of the HTTP request. This is useful when you want to modify the HTTP request without affecting the original request.
Constructor | Description |
---|---|
Http |
Create a new Http |
Http |
Create a new Http |
Http |
Create a new Http |
Http |
Create a new Http |
Http |
Create a new Http |
Modifier and Type | Method and Description |
---|---|
Http |
copy()
Creates a copy of the request. |
Flux<Byte |
get Get the request content. |
Binary |
get Get the request content. |
Http |
get Get the request headers. |
Http |
get Get the request method. |
URL |
get Get the target address. |
Http |
set Set request content. |
Http |
set Set the request content. |
Http |
set Set request content. |
Http |
set Set the request content. |
Http |
set Set a request header, replacing any existing value. |
Http |
set Deprecated
Use setHeader(HttpHeaderName headerName, String value) instead as is offers better performance.
Set a request header, replacing any existing value. |
Http |
set Set the request headers. |
Http |
set Set the request method. |
Http |
set Set the target address to send the request to. |
Http |
set Set the target address to send the request to. |
Methods inherited from java.lang.Object
HttpRequest
public HttpRequest(HttpMethod httpMethod, String url)
Create a new HttpRequest instance.
Parameters:
HttpRequest
public HttpRequest(HttpMethod httpMethod, URL url)
Create a new HttpRequest instance.
Parameters:
HttpRequest
public HttpRequest(HttpMethod httpMethod, URL url, HttpHeaders headers)
Create a new HttpRequest instance.
Parameters:
HttpRequest
public HttpRequest(HttpMethod httpMethod, URL url, HttpHeaders headers, BinaryData body)
Create a new HttpRequest instance.
Parameters:
HttpRequest
public HttpRequest(HttpMethod httpMethod, URL url, HttpHeaders headers, Flux
Create a new HttpRequest instance.
Parameters:
copy
public 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:
getBody
public Flux
Get the request content.
Returns:
getBodyAsBinaryData
public BinaryData getBodyAsBinaryData()
Get the request content.
Returns:
getHeaders
public HttpHeaders getHeaders()
Get the request headers.
Returns:
getHttpMethod
public HttpMethod getHttpMethod()
Get the request method.
Returns:
getUrl
public URL getUrl()
Get the target address.
Returns:
setBody
public HttpRequest setBody(BinaryData content)
Set request content.
If provided content has known length, i.e. getLength() returns non-null then Content-Length header is updated. Otherwise, if provided content has unknown length, i.e. 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:
Returns:
setBody
public HttpRequest setBody(byte[] content)
Set the request content.
The Content-Length header will be set based on the given content's length.
Parameters:
Returns:
setBody
public HttpRequest setBody(Flux
Set request content.
Caller must set the Content-Length header to indicate the length of the content, or use Transfer-Encoding: chunked.
Parameters:
Returns:
setBody
public HttpRequest setBody(String content)
Set the request content.
The Content-Length header will be set based on the given content's length.
Parameters:
Returns:
setHeader
public HttpRequest setHeader(HttpHeaderName headerName, String value)
Set a request header, replacing any existing value. A null for value
will remove the header if one with matching name exists.
Parameters:
Returns:
setHeader
@Deprecated
public HttpRequest setHeader(String name, String value)
Deprecated
Set a request header, replacing any existing value. A null for value
will remove the header if one with matching name exists.
Parameters:
Returns:
setHeaders
public HttpRequest setHeaders(HttpHeaders headers)
Set the request headers.
Parameters:
Returns:
setHttpMethod
public HttpRequest setHttpMethod(HttpMethod httpMethod)
Set the request method.
Parameters:
Returns:
setUrl
public HttpRequest setUrl(String url)
Set the target address to send the request to.
Parameters:
Returns:
setUrl
public HttpRequest setUrl(URL url)
Set the target address to send the request to.
Parameters:
Returns:
Azure SDK for Java-feedback
Azure SDK for Java is een open source project. Selecteer een koppeling om feedback te geven: