Hi. This is the feed program for Cosm. (The previous name of the services is Pachube.)

Dependencies:   mbed ThermistorPack Pachube ConfigFile EthernetNetIf TextLCD HTTPClient_ToBeRemoved FatFileSystem SDFileSystem

Embed: (wiki syntax)

« Back to documentation index

HTTPClient Class Reference

A simple HTTP Client. More...

#include <HTTPClient.h>

Inherits NetService, and NetService.

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.
 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.
void close ()
 This flags the service as to be destructed if owned by the pool.

Detailed Description

A simple HTTP Client.

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)

Definition at line 68 of file LPC1768/services/http/client/HTTPClient.h.


Constructor & Destructor Documentation

HTTPClient (  )

Instantiates the HTTP client.

HTTPClient (  )

Instantiates the HTTP client.


Member Function Documentation

void basicAuth ( const char *  user,
const char *  password 
)

Provides a basic authentification feature (Base64 encoded username and password)

void basicAuth ( const char *  user,
const char *  password 
)

Provides a basic authentification feature (Base64 encoded username and password)

void close (  ) [protected]

This flags the service as to be destructed if owned by the pool.

Reimplemented from NetService.

void close (  ) [protected]

This flags the service as to be destructed if owned by the pool.

Reimplemented from NetService.

void doGet ( const char *  uri,
HTTPData *  pDataIn 
)

Executes a GET Request (non blocking)

Executes a GET request on the URI uri

Parameters:
uri: URI on which to execute the request
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL The function returns immediately and calls the previously set callback on completion or error
void doGet ( const char *  uri,
HTTPData *  pDataIn 
)

Executes a GET Request (non blocking)

Executes a GET request on the URI uri

Parameters:
uri: URI on which to execute the request
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL The function returns immediately and calls the previously set callback on completion or error
void doPost ( const char *  uri,
const HTTPData &  dataOut,
HTTPData *  pDataIn 
)

Executes a POST Request (non blocking)

Executes a POST request on the URI uri

Parameters:
uri: URI on which to execute the request
dataOut: a HTTPData instance that contains the data that will be posted
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL
pMethod: callback function The function returns immediately and calls the previously set callback on completion or error
void doPost ( const char *  uri,
const HTTPData &  dataOut,
HTTPData *  pDataIn 
)

Executes a POST Request (non blocking)

Executes a POST request on the URI uri

Parameters:
uri: URI on which to execute the request
dataOut: a HTTPData instance that contains the data that will be posted
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL
pMethod: callback function The function returns immediately and calls the previously set callback on completion or error
HTTPResult get ( const char *  uri,
HTTPData *  pDataIn,
T *  pItem,
void(T::*)(HTTPResult pMethod 
)

Executes a GET Request (non blocking)

Executes a GET request on the URI uri

Parameters:
uri: URI on which to execute the request
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL
pItem: instance of class on which to execute the callback method
pMethod: callback method The function returns immediately and calls the callback on completion or error

Definition at line 108 of file LPC1768/services/http/client/HTTPClient.h.

HTTPResult get ( const char *  uri,
HTTPData *  pDataIn,
void(*)(HTTPResult pMethod 
)

Executes a GET Request (non blocking)

Executes a GET request on the URI uri

Parameters:
uri: URI on which to execute the request
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL
pMethod: callback function The function returns immediately and calls the callback on completion or error
HTTPResult get ( const char *  uri,
HTTPData *  pDataIn,
T *  pItem,
void(T::*)(HTTPResult pMethod 
)

Executes a GET Request (non blocking)

Executes a GET request on the URI uri

Parameters:
uri: URI on which to execute the request
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL
pItem: instance of class on which to execute the callback method
pMethod: callback method The function returns immediately and calls the callback on completion or error

Definition at line 108 of file LPC2368/services/http/client/HTTPClient.h.

HTTPResult get ( const char *  uri,
HTTPData *  pDataIn 
)

Executes a GET Request (blocking)

Executes a GET request on the URI uri

Parameters:
uri: URI on which to execute the request
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL Blocks until completion
HTTPResult get ( const char *  uri,
HTTPData *  pDataIn,
void(*)(HTTPResult pMethod 
)

Executes a GET Request (non blocking)

Executes a GET request on the URI uri

Parameters:
uri: URI on which to execute the request
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL
pMethod: callback function The function returns immediately and calls the callback on completion or error
HTTPResult get ( const char *  uri,
HTTPData *  pDataIn 
)

Executes a GET Request (blocking)

Executes a GET request on the URI uri

Parameters:
uri: URI on which to execute the request
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL Blocks until completion
int getHTTPResponseCode (  )

Gets last request's HTTP response code.

Returns:
The HTTP response code of the last request
int getHTTPResponseCode (  )

Gets last request's HTTP response code.

Returns:
The HTTP response code of the last request
string& getResponseHeader ( const string &  header )

Gets a response header.

string& getResponseHeader ( const string &  header )

Gets a response header.

virtual void poll (  ) [virtual]

This method can be inherited so that it is called on each Net::poll() call.

Reimplemented from NetService.

virtual void poll (  ) [virtual]

This method can be inherited so that it is called on each Net::poll() call.

Reimplemented from NetService.

HTTPResult post ( const char *  uri,
const HTTPData &  dataOut,
HTTPData *  pDataIn 
)

Executes a POST Request (blocking)

Executes a POST request on the URI uri

Parameters:
uri: URI on which to execute the request
dataOut: a HTTPData instance that contains the data that will be posted
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL Blocks until completion
HTTPResult post ( const char *  uri,
const HTTPData &  dataOut,
HTTPData *  pDataIn,
void(*)(HTTPResult pMethod 
)

Executes a POST Request (non blocking)

Executes a POST request on the URI uri

Parameters:
uri: URI on which to execute the request
dataOut: a HTTPData instance that contains the data that will be posted
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL
pMethod: callback function The function returns immediately and calls the callback on completion or error
HTTPResult post ( const char *  uri,
const HTTPData &  dataOut,
HTTPData *  pDataIn,
T *  pItem,
void(T::*)(HTTPResult pMethod 
)

Executes a POST Request (non blocking)

Executes a POST request on the URI uri

Parameters:
uri: URI on which to execute the request
dataOut: a HTTPData instance that contains the data that will be posted
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL
pItem: instance of class on which to execute the callback method
pMethod: callback method The function returns immediately and calls the callback on completion or error

Definition at line 147 of file LPC2368/services/http/client/HTTPClient.h.

HTTPResult post ( const char *  uri,
const HTTPData &  dataOut,
HTTPData *  pDataIn 
)

Executes a POST Request (blocking)

Executes a POST request on the URI uri

Parameters:
uri: URI on which to execute the request
dataOut: a HTTPData instance that contains the data that will be posted
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL Blocks until completion
HTTPResult post ( const char *  uri,
const HTTPData &  dataOut,
HTTPData *  pDataIn,
void(*)(HTTPResult pMethod 
)

Executes a POST Request (non blocking)

Executes a POST request on the URI uri

Parameters:
uri: URI on which to execute the request
dataOut: a HTTPData instance that contains the data that will be posted
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL
pMethod: callback function The function returns immediately and calls the callback on completion or error
HTTPResult post ( const char *  uri,
const HTTPData &  dataOut,
HTTPData *  pDataIn,
T *  pItem,
void(T::*)(HTTPResult pMethod 
)

Executes a POST Request (non blocking)

Executes a POST request on the URI uri

Parameters:
uri: URI on which to execute the request
dataOut: a HTTPData instance that contains the data that will be posted
pDataIn: pointer to an HTTPData instance that will collect the data returned by the request, can be NULL
pItem: instance of class on which to execute the callback method
pMethod: callback method The function returns immediately and calls the callback on completion or error

Definition at line 147 of file LPC1768/services/http/client/HTTPClient.h.

void resetRequestHeaders (  )

Clears request headers.

void resetRequestHeaders (  )

Clears request headers.

void setOnResult ( void(*)(HTTPResult pMethod )

Setups the result callback.

Parameters:
pMethod: callback function
void setOnResult ( void(*)(HTTPResult pMethod )

Setups the result callback.

Parameters:
pMethod: callback function
void setRequestHeader ( const string &  header,
const string &  value 
)

Sets a specific request header.

void setRequestHeader ( const string &  header,
const string &  value 
)

Sets a specific request header.

void setTimeout ( int  ms )

Setups timeout.

Parameters:
ms: time of connection inactivity in ms after which the request should timeout
void setTimeout ( int  ms )

Setups timeout.

Parameters:
ms: time of connection inactivity in ms after which the request should timeout