Package com.azure.android.core.http
Class HttpRequest
- java.lang.Object
-
- com.azure.android.core.http.HttpRequest
-
public class HttpRequest extends java.lang.Object
The outgoing Http request. It provides ways to constructHttpRequest
withHttpMethod
,url
,HttpHeader
and request body.
-
-
Constructor Summary
Constructors Constructor Description HttpRequest(HttpMethod httpMethod, java.lang.String url)
Create a new HttpRequest instance.HttpRequest(HttpMethod httpMethod, java.lang.String url, HttpHeaders headers, byte[] body)
Create a new HttpRequest instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpRequest
copy()
Creates a copy of the request.byte[]
getBody()
Get the request content.HttpHeaders
getHeaders()
Get the request headers.HttpMethod
getHttpMethod()
Get the request method.java.util.Map<java.lang.Object,java.lang.Object>
getTags()
Gets the tags-store associated with the request.java.net.URL
getUrl()
Get the target address.HttpRequest
setBody(byte[] content)
Set the request content.HttpRequest
setBody(java.lang.String content)
Set the request content.HttpRequest
setHeader(java.lang.String name, java.lang.String value)
Set a request header, replacing any existing value.HttpRequest
setHeaders(HttpHeaders headers)
Set the request headers.HttpRequest
setHttpMethod(HttpMethod httpMethod)
Set the request method.HttpRequest
setUrl(java.lang.String url)
Set the target address to send the request to.
-
-
-
Constructor Detail
-
HttpRequest
public HttpRequest(HttpMethod httpMethod, java.lang.String url)
Create a new HttpRequest instance.- Parameters:
httpMethod
- The HTTP request method.url
- The target address to send the request to.- Throws:
java.lang.IllegalArgumentException
- if the url is malformed.
-
HttpRequest
public HttpRequest(HttpMethod httpMethod, java.lang.String url, HttpHeaders headers, byte[] body)
Create a new HttpRequest instance.- Parameters:
httpMethod
- The HTTP request method.url
- The target address to send the request to.headers
- The HTTP headers to use with this request.body
- The request content.- Throws:
java.lang.IllegalArgumentException
- if the url is malformed.
-
-
Method Detail
-
getHttpMethod
public HttpMethod getHttpMethod()
Get the request method.- Returns:
- the request method
-
setHttpMethod
public HttpRequest setHttpMethod(HttpMethod httpMethod)
Set the request method.- Parameters:
httpMethod
- the request method- Returns:
- this HttpRequest
-
getUrl
public java.net.URL getUrl()
Get the target address.- Returns:
- the target address
-
setUrl
public HttpRequest setUrl(java.lang.String url)
Set the target address to send the request to.- Parameters:
url
- target address.- Returns:
- this HttpRequest
- Throws:
java.lang.IllegalArgumentException
- if the url is malformed.
-
getHeaders
public HttpHeaders getHeaders()
Get the request headers.- Returns:
- headers to be sent
-
setHeaders
public HttpRequest setHeaders(HttpHeaders headers)
Set the request headers.- Parameters:
headers
- the set of headers- Returns:
- this HttpRequest
-
setHeader
public HttpRequest setHeader(java.lang.String name, java.lang.String value)
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
-
getBody
public byte[] getBody()
Get the request content.- Returns:
- the content to be send
-
setBody
public HttpRequest setBody(java.lang.String content)
Set the request content.- Parameters:
content
- the request content- Returns:
- this HttpRequest
-
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:
content
- the request content- Returns:
- this HttpRequest
-
getTags
public java.util.Map<java.lang.Object,java.lang.Object> getTags()
Gets the tags-store associated with the request.Tags are key-value data stored in a map and carried with the request. Use it to store any arbitrary data (such as debugging info) that you want to access from the request later in the call stack.
- Returns:
- The tags.
-
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:
- a new HTTP request instance with cloned instances of all mutable properties.
-
-