HTTP and HTTPS library for Mbed OS 5

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

Embed: (wiki syntax)

« Back to documentation index

HttpRequest Class Reference

HttpRequest Class Reference

HttpRequest implements the logic for interacting with HTTP servers. More...

#include <http_request.h>

Inherits HttpRequestBase.

Public Member Functions

 HttpRequest (NetworkInterface *network, http_method method, const char *url, Callback< void(const char *at, uint32_t length)> bodyCallback=0)
 HttpRequest Constructor.
 HttpRequest (TCPSocket *socket, http_method method, const char *url, Callback< void(const char *at, uint32_t length)> bodyCallback=0)
 HttpRequest Constructor.
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.

Friends

class HttpRequestBase

Detailed Description

HttpRequest implements the logic for interacting with HTTP servers.

Definition at line 40 of file http_request.h.


Constructor & Destructor Documentation

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

HttpRequest Constructor.

Parameters:
[in]networkThe network interface
[in]methodHTTP method to use
[in]urlURL to the resource
[in]bodyCallbackCallback 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 54 of file http_request.h.

HttpRequest ( TCPSocket *  socket,
http_method  method,
const char *  url,
Callback< void(const char *at, uint32_t length)>  bodyCallback = 0 
)

HttpRequest Constructor.

Parameters:
[in]socketAn open TCPSocket
[in]methodHTTP method to use
[in]urlURL to the resource
[in]bodyCallbackCallback 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 78 of file http_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.