HttpsConnection Class
- java.
lang. Object - com.
microsoft. azure. sdk. iot. device. transport. https. HttpsConnection
- com.
public class HttpsConnection
A wrapper for the Java SE class HttpsURLConnection. Used to avoid compatibility issues when testing with the mocking framework JMockit, as well as to avoid some undocumented side effects when using HttpsURLConnection.
The underlying HttpsURLConnection is transparently managed by Java. To reuse connections, for each time connect() is called, the input streams (input stream or error stream, if input stream is not accessible) must be completely read. Otherwise, the data remains in the stream and the connection will not be reusable.
Constructor Summary
Modifier | Constructor | Description | |
---|---|---|---|
protected | HttpsConnection() | ||
HttpsConnection(URL url, HttpsMethod method) |
Constructor. |
||
HttpsConnection(URL url, HttpsMethod method, ProxySettings proxySettings) |
Constructor. |
||
HttpsConnection(URL url, HttpsMethod method, ProxySettings proxySettings, boolean isHttps) |
Constructor. |
Method Summary
Modifier and Type | Method and Description |
---|---|
void |
connect()
Sends the request to the URL given in the constructor. |
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getResponseHeaders()
Returns the response headers as a Map, where the key is the header field name and the values are the values associated with the header field name. |
int |
getResponseStatus()
Returns the response status code. |
byte[] |
readError()
Reads from the error stream and returns the error reason. |
byte[] |
readInput()
Reads from the input stream (response stream) and returns the response. |
void |
setConnectTimeout(int timeout)
Sets the connect timeout in milliseconds. |
void |
setReadTimeout(int timeout)
Sets the read timeout in milliseconds. |
void |
setRequestHeader(String field, String value)
Sets the request header field to the given value. |
void |
setRequestMethod(HttpsMethod method)
Sets the request method (i. |
void |
writeOutput(byte[] body)
Saves the body to be sent with the request. |
Methods inherited from java.lang.Object
Constructor Details
HttpsConnection
protected HttpsConnection()
HttpsConnection
public HttpsConnection(URL url, HttpsMethod method)
Constructor. Opens a connection to the given URL. Can be HTTPS or HTTP
Parameters:
Throws:
HttpsConnection
public HttpsConnection(URL url, HttpsMethod method, ProxySettings proxySettings)
Constructor. Opens a connection to the given URL. Can be HTTPS or HTTP
Parameters:
Throws:
HttpsConnection
public HttpsConnection(URL url, HttpsMethod method, ProxySettings proxySettings, boolean isHttps)
Constructor. Opens a connection to the given URL. Can be HTTPS or HTTP
Parameters:
Throws:
Method Details
connect
public void connect()
Sends the request to the URL given in the constructor.
Throws:
getResponseHeaders
public Map
Returns the response headers as a Map, where the key is the header field name and the values are the values associated with the header field name.
Returns:
getResponseStatus
public int getResponseStatus()
Returns the response status code.
Returns:
Throws:
readError
public byte[] readError()
Reads from the error stream and returns the error reason.
Returns:
Throws:
readInput
public byte[] readInput()
Reads from the input stream (response stream) and returns the response.
Returns:
Throws:
setConnectTimeout
public void setConnectTimeout(int timeout)
Sets the connect timeout in milliseconds.
Parameters:
setReadTimeout
public void setReadTimeout(int timeout)
Sets the read timeout in milliseconds. The read timeout is the number of milliseconds after the server receives a request and before the server sends data back.
Parameters:
setRequestHeader
public void setRequestHeader(String field, String value)
Sets the request header field to the given value.
Parameters:
setRequestMethod
public void setRequestMethod(HttpsMethod method)
Sets the request method (i.e. POST).
Parameters:
Throws:
writeOutput
public void writeOutput(byte[] body)
Saves the body to be sent with the request.
Parameters:
Throws:
Applies to
Azure SDK for Java