HTTP Client

New examples for mbed OS 5

This is a deprecated page for mbed OS 2. There is an updated HTTP/HTTPS library for mbed OS 5 available at sandbox/http-example.

This page explains how to do HTTP requests from your mbed. It uses the Networking stack.

Hello World!

If you haven't done it yet, try out the simple Working with the networking stack example program.

Packages

Precompiled version:

Import libraryHTTPClient_ToBeRemoved

HTTP Client library

Library

Architecture

The HTTPClient is composed of:

  • The actual client (HTTPClient)
  • Classes that act as a data repository, each of which deriving from the HTTPData class (HTTPText for short text content, HTTPFile for file I/O, HTTPMap for key/value pairs, and HTTPStream for streaming purposes)

HTTP Client Data Containers

  • HTTPText
  • HTTPMap
  • HTTPFile
  • HTTPStream

See HTTP Client Data Containers

Includes

#include "HTTPClient.h"

Reference

Import program

Public Member Functions

HTTPClient ()
Instantiates the HTTP client.
void basicAuth (const char *user, const char *password)
Provides a basic authentification feature (Base64 encoded username and password)
HTTPResult get (const char *uri, HTTPData *pDataIn)
Executes a GET Request (blocking)
HTTPResult get (const char *uri, HTTPData *pDataIn, void(*pMethod)( HTTPResult ))
Executes a GET Request (non blocking)
template<class T >
HTTPResult get (const char *uri, HTTPData *pDataIn, T *pItem, void(T::*pMethod)( HTTPResult ))
Executes a GET Request (non blocking)
HTTPResult post (const char *uri, const HTTPData &dataOut, HTTPData *pDataIn)
Executes a POST Request (blocking)
HTTPResult post (const char *uri, const HTTPData &dataOut, HTTPData *pDataIn, void(*pMethod)( HTTPResult ))
Executes a POST Request (non blocking)
template<class T >
HTTPResult post (const char *uri, const HTTPData &dataOut, HTTPData *pDataIn, T *pItem, void(T::*pMethod)( HTTPResult ))
Executes a POST Request (non blocking)
void doGet (const char *uri, HTTPData *pDataIn)
Executes a GET Request (non blocking)
void doPost (const char *uri, const HTTPData &dataOut, HTTPData *pDataIn)
Executes a POST Request (non blocking)
void setOnResult (void(*pMethod)( HTTPResult ))
Setups the result callback.
void setTimeout (int ms)
Setups timeout.
virtual void poll ()
This method can be inherited so that it is called on each Net::poll() call.
int getHTTPResponseCode ()
Gets last request's HTTP response code.
void setRequestHeader (const string &header, const string &value)
Sets a specific request header.
string & getResponseHeader (const string &header)
Gets a response header.
void resetRequestHeaders ()
Clears request headers.

Protected Member Functions

void close ()
This flags the service as to be destructed if owned by the pool.

Examples

Have a look at the Working with the networking stack and Twitter examples.

License


All wikipages