This library is used to make HTTP and HTTPS calls from mbed OS 5 applications.

Fork of mbed-http by sandbox

Embed: (wiki syntax)

« Back to documentation index

HttpsRequest Class Reference

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

#include <https_request.h>

Public Member Functions

 HttpsRequest (NetworkInterface *net_iface, const char *ssl_ca_pem, http_method method, const char *url, Callback< void(const char *at, size_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, size_t length)> body_callback=0)
 HttpsRequest Constructor Sets up event handlers and flags.
 ~HttpsRequest ()
 HttpsRequest Destructor.
HttpResponse * send (const void *body=NULL, nsapi_size_t body_size=0)
 Execute the HTTPS request.
void close ()
 Closes the underlying TCP socket.
void set_header (string key, string value)
 Set a header for the request.
nsapi_error_t get_error ()
 Get the error code.
void set_debug (bool debug)
 Set the debug flag.

Static Protected Member Functions

static void print_mbedtls_error (const char *name, int err)
 Helper for pretty-printing mbed TLS error codes.

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 *  net_iface,
const char *  ssl_ca_pem,
http_method  method,
const char *  url,
Callback< void(const char *at, size_t length)>  body_callback = 0 
)

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

Parameters:
[in]net_ifaceThe 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, size_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 75 of file https_request.h.

~HttpsRequest (  )

HttpsRequest Destructor.

Definition at line 93 of file https_request.h.


Member Function Documentation

void close (  )

Closes the underlying TCP socket.

Definition at line 210 of file https_request.h.

nsapi_error_t get_error (  )

Get the error code.

When send() fails, this error is set.

Definition at line 232 of file https_request.h.

static void print_mbedtls_error ( const char *  name,
int  err 
) [static, protected]

Helper for pretty-printing mbed TLS error codes.

Definition at line 252 of file https_request.h.

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

Execute the HTTPS request.

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

Definition at line 119 of file https_request.h.

void set_debug ( bool  debug )

Set the debug flag.

If this flag is set, debug information from mbed TLS will be logged to stdout.

Definition at line 241 of file https_request.h.

void set_header ( string  key,
string  value 
)

Set a header for the request.

The 'Host' and 'Content-Length' headers are set automatically. Setting the same header twice will overwrite the previous entry.

Parameters:
[in]keyHeader key
[in]valueHeader value

Definition at line 223 of file https_request.h.