HTTP Client
.
This page explains how to do HTTP requests from your mbed.
Library
Import libraryHTTPClient
A HTTP Client for the mbed networking libraries
Architecture
The HTTPClient is composed of:
- The actual client (HTTPClient)
- Classes that act as a data repository, each of which deriving from the IHTTPDataIn/IHTTPDataOut interfaces (HTTPText for text content, HTTPMap for key/value pairs)
HTTP Client Data Containers
- HTTPText
Import library
Public Member Functions |
|
HTTPText (char *str) | |
Create an
HTTPText
instance for output.
|
|
HTTPText (char *str, size_t size) | |
Create an
HTTPText
instance for input.
|
|
Protected Member Functions |
|
virtual void | readReset () |
Reset stream to its beginning Called by the
HTTPClient
on each new request.
|
|
virtual int | read (char *buf, size_t len, size_t *pReadLen) |
Read a piece of data to be transmitted.
|
|
virtual int | getDataType (char *type, size_t maxTypeLen) |
Get MIME type.
|
|
virtual bool | getIsChunked () |
Determine whether the HTTP client should chunk the data Used for Transfer-Encoding header.
|
|
virtual size_t | getDataLen () |
If the data is not chunked, get its size Used for Content-Length header.
|
|
virtual void | writeReset () |
Reset stream to its beginning Called by the
HTTPClient
on each new request.
|
|
virtual int | write (const char *buf, size_t len) |
Write a piece of data transmitted by the server.
|
|
virtual void | setDataType (const char *type) |
Set MIME type.
|
|
virtual void | setIsChunked (bool chunked) |
Determine whether the data is chunked Recovered from Transfer-Encoding header.
|
|
virtual void | setDataLen (size_t len) |
If the data is not chunked, set its size From Content-Length header.
|
|
virtual bool | getHeader (char *header, size_t maxHeaderLen) |
Get a specific header.
|
|
Friends |
|
class | HTTPClient |
class | HTTPClient |
- HTTPMap
Import library
Public Member Functions |
|
HTTPMap () | |
Instantiates
HTTPMap
It supports at most 32 key/values pairs.
|
|
void | put (const char *key, const char *value) |
Put Key/Value pair The references to the parameters must remain valid as long as the
clear()
function is not called.
|
|
void | clear () |
Clear table.
|
|
Protected Member Functions |
|
virtual void | readReset () |
Reset stream to its beginning Called by the
HTTPClient
on each new request.
|
|
virtual int | read (char *buf, size_t len, size_t *pReadLen) |
Read a piece of data to be transmitted.
|
|
virtual int | getDataType (char *type, size_t maxTypeLen) |
Get MIME type.
|
|
virtual bool | getIsChunked () |
Determine whether the HTTP client should chunk the data Used for Transfer-Encoding header.
|
|
virtual size_t | getDataLen () |
If the data is not chunked, get its size Used for Content-Length header.
|
|
virtual bool | getHeader (char *header, size_t maxHeaderLen) |
Get a specific header.
|
|
Friends |
|
class | HTTPClient |
Includes
#include "HTTPClient.h"
Reference
Import library
Public Member Functions |
|
HTTPClient () | |
Instantiate the HTTP client.
|
|
void | basicAuth (const char *user, const char *password) |
Provides a basic authentification feature (Base64 encoded username and password) Pass two NULL pointers to switch back to no authentication.
|
|
HTTPResult | get (const char *url, IHTTPDataIn *pDataIn, int timeout=HTTP_CLIENT_DEFAULT_TIMEOUT) |
Execute a GET request on the URL Blocks until completion.
|
|
HTTPResult | get (const char *url, char *result, size_t maxResultLen, int timeout=HTTP_CLIENT_DEFAULT_TIMEOUT) |
Execute a GET request on the URL Blocks until completion This is a helper to directly get a piece of text from a HTTP result.
|
|
HTTPResult | post (const char *url, const IHTTPDataOut &dataOut, IHTTPDataIn *pDataIn, int timeout=HTTP_CLIENT_DEFAULT_TIMEOUT) |
Execute a POST request on the URL Blocks until completion.
|
|
HTTPResult | put (const char *url, const IHTTPDataOut &dataOut, IHTTPDataIn *pDataIn, int timeout=HTTP_CLIENT_DEFAULT_TIMEOUT) |
Execute a PUT request on the URL Blocks until completion.
|
|
HTTPResult | del (const char *url, IHTTPDataIn *pDataIn, int timeout=HTTP_CLIENT_DEFAULT_TIMEOUT) |
Execute a DELETE request on the URL Blocks until completion.
|
|
int | getHTTPResponseCode () |
Get last request's HTTP response code.
|
Example
Here is a program that tests both GET and POST data over a 3G connection.
Import programVodafoneUSBModemHTTPClientTest
Example demonstrating the use of the Vodafone USB Modem library with the HTTP Client
This is the same program over Ethernet with demos of PUT & DELETE requests as well.
Import programHTTPClient_HelloWorld
Simple example demonstrating how to use GET & POST requests with the HTTP Client
4 comments on HTTP Client:
Please log in to post comments.
i got this error on you super tweet example "cannot open source input file "TCPSocketConnection.h": No such file or directory" in file "HTTPClientHTTPClient.h", Line: 27, Col: 32" can you tellme the resion