Fork of mbed-http

Fork of mbed-http by sandbox

Embed: (wiki syntax)

« Back to documentation index

HttpRequest Class Reference

HttpRequest Class Reference

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

#include <http_request.h>

Public Member Functions

 HttpRequest (NetworkInterface *aNetwork, http_method aMethod, const char *url, Callback< void(const char *at, size_t length)> aBodyCallback=0)
 HttpRequest Constructor.
 HttpRequest (TCPSocket *aSocket, http_method aMethod, const char *url, Callback< void(const char *at, size_t length)> aBodyCallback=0)
 HttpRequest Constructor.
 ~HttpRequest ()
 HttpRequest Constructor.
HttpResponse * send (const void *body=NULL, nsapi_size_t body_size=0)
 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.

Detailed Description

HttpRequest implements the logic for interacting with HTTPS servers.

Definition at line 39 of file http_request.h.


Constructor & Destructor Documentation

HttpRequest ( NetworkInterface *  aNetwork,
http_method  aMethod,
const char *  url,
Callback< void(const char *at, size_t length)>  aBodyCallback = 0 
)

HttpRequest Constructor.

Parameters:
[in]aNetworkThe network interface
[in]aMethodHTTP method to use
[in]urlURL to the resource
[in]aBodyCallbackCallback 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 51 of file http_request.h.

HttpRequest ( TCPSocket *  aSocket,
http_method  aMethod,
const char *  url,
Callback< void(const char *at, size_t length)>  aBodyCallback = 0 
)

HttpRequest Constructor.

Parameters:
[in]aSocketAn open TCPSocket
[in]aMethodHTTP method to use
[in]urlURL to the resource
[in]aBodyCallbackCallback 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 74 of file http_request.h.

~HttpRequest (  )

HttpRequest Constructor.

Definition at line 90 of file http_request.h.


Member Function Documentation

nsapi_error_t get_error (  )

Get the error code.

When send() fails, this error is set.

Definition at line 218 of file http_request.h.

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

Execute the request and receive the response.

Definition at line 113 of file http_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 209 of file http_request.h.