HttpRequest Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.service.transport.http.HttpRequest

public class HttpRequest

Field Summary

Modifier and Type Field and Description
final String IF_MATCH
final String REQUEST_ID

Constructor Summary

Constructor Description
HttpRequest()
HttpRequest(URL url, HttpMethod method, byte[] body, String authorizationToken)

Constructor. Takes a URL as an argument and returns an HTTPS request that is ready to be sent.

HttpRequest(URL url, HttpMethod method, byte[] body, String authorizationToken, Proxy proxy)

Constructor. Takes a URL as an argument and returns an HTTPS request that is ready to be sent through an optional proxy.

Method Summary

Modifier and Type Method and Description
HttpResponse send()

Executes the HTTPS request.

HttpRequest setConnectTimeoutSeconds(int timeout)

Set the connect timeout, in seconds, for the request. The connect timeout is the allowed amount of time for the http connection to be established.

HttpRequest setHeaderField(String field, String value)

Sets the header field to the given value.

HttpRequest setHeaders(Map<String, String> headers)

Sets the header field to the given value.

HttpRequest setReadTimeoutSeconds(int timeout)

Sets the read timeout, in seconds, for the request. The read timeout is the number of milliseconds after the server receives a request and before the server sends data back.

Field Details

IF_MATCH

public static final String IF_MATCH= "If-Match"

REQUEST_ID

public static final String REQUEST_ID= "Request-Id"

Constructor Details

HttpRequest

protected HttpRequest()

HttpRequest

public HttpRequest(URL url, HttpMethod method, byte[] body, String authorizationToken)

Constructor. Takes a URL as an argument and returns an HTTPS request that is ready to be sent.

Parameters:

url - The URL for the request.
method - The HTTPS request method (i.e. GET).
body - The request body. Must be an array of size 0 if the request method is GET or DELETE.
authorizationToken - The header value for the Authorization header.

Throws:

IOException - This exception thrown if an IOException occurs in setting up the HTTPS connection.
IllegalArgumentException - This exception thrown if the endpoint given does not use the HTTPS protocol.

HttpRequest

public HttpRequest(URL url, HttpMethod method, byte[] body, String authorizationToken, Proxy proxy)

Constructor. Takes a URL as an argument and returns an HTTPS request that is ready to be sent through an optional proxy.

Parameters:

url - The URL for the request.
method - The HTTPS request method (i.e. GET).
body - The request body. Must be an array of size 0 if the request method is GET or DELETE.
authorizationToken - The header value for the Authorization header.
proxy - The proxy to send the request through. May be null if no proxy should be used

Throws:

IOException - This exception thrown if an IOException occurs in setting up the HTTPS connection.
IllegalArgumentException - This exception thrown if the endpoint given does not use the HTTPS protocol.

Method Details

send

public HttpResponse send()

Executes the HTTPS request.

Returns:

The HTTPS response.

Throws:

IOException - This exception thrown if the connection could not be established, or the input/output streams could not be accessed.
IotHubException - if the http request was successful, but IoT hub responded with an error code

setConnectTimeoutSeconds

public HttpRequest setConnectTimeoutSeconds(int timeout)

Set the connect timeout, in seconds, for the request. The connect timeout is the allowed amount of time for the http connection to be established.

Parameters:

timeout - the connect timeout

Returns:

the object itself, for fluent setting.

setHeaderField

public HttpRequest setHeaderField(String field, String value)

Sets the header field to the given value.

Parameters:

field - The header field name.
value - The header field value.

Returns:

The object itself, for fluent setting.

setHeaders

public HttpRequest setHeaders(Map headers)

Sets the header field to the given value.

Parameters:

headers - The set of headers to use for this request

Returns:

The object itself, for fluent setting.

setReadTimeoutSeconds

public HttpRequest setReadTimeoutSeconds(int timeout)

Sets the read timeout, in seconds, for the request. The read timeout is the number of milliseconds after the server receives a request and before the server sends data back.

Parameters:

timeout - The read timeout.

Returns:

The object itself, for fluent setting.

Applies to