Share via


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
protected final HttpConnection connection

The underlying HTTPS connection stream.

Constructor Summary

Modifier Constructor Description
protected HttpRequest()
HttpRequest(URL url, HttpMethod method, byte[] body)

Constructor.

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

Constructor.

Method Summary

Modifier and Type Method and Description
HttpResponse send()

Executes the HTTPS request.

HttpRequest setConnectTimeoutMillis(int timeout)

Set the connect timeout, in milliseconds, for the request.

HttpRequest setHeaderField(String field, String value)

Sets the header field to the given value.

HttpRequest setReadTimeoutMillis(int timeout)

Sets the read timeout, in milliseconds, for the request.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Field Details

connection

protected final HttpConnection connection

The underlying HTTPS connection stream.

Constructor Details

HttpRequest

protected HttpRequest()

HttpRequest

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

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.

Throws:

java.io.IOException - This exception thrown if an IOException occurs in setting up the HTTPS connection.

HttpRequest

public HttpRequest(URL url, HttpMethod method, byte[] body, 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.
proxy - The proxy to send the request through. May be null if no proxy should be used

Throws:

java.io.IOException - This exception thrown if an IOException occurs in setting up the HTTPS connection.

Method Details

send

public HttpResponse send()

Executes the HTTPS request.

Returns:

The HTTPS response.

Throws:

java.io.IOException - This exception thrown if the connection could not be established, or the input/output streams could not be accessed.

setConnectTimeoutMillis

public HttpRequest setConnectTimeoutMillis(int timeout)

Set the connect timeout, in milliseconds, 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.

setReadTimeoutMillis

public HttpRequest setReadTimeoutMillis(int timeout)

Sets the read timeout, in milliseconds, 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