HTTP and HTTPS library for Mbed OS 5

Dependents:   MQTTGateway2 MQTTGatewayK64 http-example-wnc GuardRoom ... more

Embed: (wiki syntax)

« Back to documentation index

HttpsRequest Class Reference

HttpsRequest Class Reference

HttpsRequest implements the logic for interacting with HTTPS servers. More...

#include <https_request.h>

Inherits HttpRequestBase.

Public Member Functions

 HttpsRequest (NetworkInterface *network, const char *ssl_ca_pem, http_method method, const char *url, Callback< void(const char *at, uint32_t length)> body_callback=0)
 HttpsRequest Constructor Initializes the TCP socket, sets up event handlers and flags.
 HttpsRequest (TLSSocket *socket, http_method method, const char *url, Callback< void(const char *at, uint32_t length)> body_callback=0)
 HttpsRequest Constructor Sets up event handlers and flags.
HttpResponse * send (const void *body=NULL, nsapi_size_t body_size=0)
 Execute the request and receive the response.
HttpResponse * send (Callback< const void *(uint32_t *)> body_cb)
 Execute the request and receive the response.
void set_header (string key, string value)
 Set a header for the request.
nsapi_error_t get_error ()
 Get the error code.
void set_request_log_buffer (uint8_t *buffer, size_t buffer_size)
 Set the request log buffer, all bytes that are sent for this request are logged here.
size_t get_request_log_buffer_length ()
 Get the number of bytes written to the request log buffer, since the last request.

Detailed Description

HttpsRequest implements the logic for interacting with HTTPS servers.

Definition at line 34 of file https_request.h.


Constructor & Destructor Documentation

HttpsRequest ( NetworkInterface *  network,
const char *  ssl_ca_pem,
http_method  method,
const char *  url,
Callback< void(const char *at, uint32_t length)>  body_callback = 0 
)

HttpsRequest Constructor Initializes the TCP socket, sets up event handlers and flags.

Parameters:
[in]networkThe network interface
[in]ssl_ca_pemString containing the trusted CAs
[in]methodHTTP method to use
[in]urlURL to the resource
[in]body_callbackCallback on which to retrieve chunks of the response body. If not set, the complete body will be allocated on the HttpResponse object, which might use lots of memory.

Definition at line 48 of file https_request.h.

HttpsRequest ( TLSSocket *  socket,
http_method  method,
const char *  url,
Callback< void(const char *at, uint32_t length)>  body_callback = 0 
)

HttpsRequest Constructor Sets up event handlers and flags.

Parameters:
[in]socketA connected TLSSocket
[in]methodHTTP method to use
[in]urlURL to the resource
[in]body_callbackCallback on which to retrieve chunks of the response body. If not set, the complete body will be allocated on the HttpResponse object, which might use lots of memory.

Definition at line 76 of file https_request.h.


Member Function Documentation

nsapi_error_t get_error (  ) [inherited]

Get the error code.

When send() fails, this error is set.

Definition at line 210 of file http_request_base.h.

size_t get_request_log_buffer_length (  ) [inherited]

Get the number of bytes written to the request log buffer, since the last request.

If no request was sent, or if the request log buffer is NULL, then this returns 0.

Definition at line 231 of file http_request_base.h.

HttpResponse* send ( const void *  body = NULL,
nsapi_size_t  body_size = 0 
) [inherited]

Execute the request and receive the response.

This adds a Content-Length header to the request (when body_size is set), and sends the data to the server.

Parameters:
bodyPointer to the body to be sent
body_sizeSize of the body to be sent
Returns:
An HttpResponse pointer on success, or NULL on failure. See get_error() for the error code.

Definition at line 88 of file http_request_base.h.

HttpResponse* send ( Callback< const void *(uint32_t *)>  body_cb ) [inherited]

Execute the request and receive the response.

This sends the request through chunked-encoding.

Parameters:
body_cbCallback which generates the next chunk of the request
Returns:
An HttpResponse pointer on success, or NULL on failure. See get_error() for the error code.

Definition at line 120 of file http_request_base.h.

void set_header ( string  key,
string  value 
) [inherited]

Set a header for the request.

The 'Host', 'Content-Length', and (optionally) 'Transfer-Encoding: chunked' headers are set automatically. Setting the same header twice will overwrite the previous entry.

Parameters:
keyHeader key
valueHeader value

Definition at line 201 of file http_request_base.h.

void set_request_log_buffer ( uint8_t *  buffer,
size_t  buffer_size 
) [inherited]

Set the request log buffer, all bytes that are sent for this request are logged here.

If the buffer would overflow logging is stopped.

Parameters:
bufferPointer to a buffer to store the data in
buffer_sizeSize of the buffer

Definition at line 221 of file http_request_base.h.