Host library for controlling a WiConnect enabled Wi-Fi module.

Dependents:   wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more

Embed: (wiki syntax)

« Back to documentation index

HTTP Methods

HTTP Methods
[Socket]

HTTP methods. More...

Functions

WiconnectResult httpConnect (WiconnectSocket &socket, const char *url, const HttpSocketArgs *args)
 Connect to remote HTTP server.
WiconnectResult httpGet (WiconnectSocket &socket, const char *url, bool openOnly=false, const char *certFilename=NULL)
 Issue HTTP GET Request.
WiconnectResult httpPost (WiconnectSocket &socket, const char *url, const char *contextType, bool openOnly=true, const char *certFilename=NULL)
 Issue HTTP POST Request.
WiconnectResult httpHead (WiconnectSocket &socket, const char *url, const char *certFilename=NULL)
 Issue HTTP HEAD Request.
WiconnectResult httpAddHeader (WiconnectSocket &socket, const char *key, const char *value)
 Add HTTP header key/value pair to opened HTTP request.
WiconnectResult httpGetStatus (WiconnectSocket &socket, uint32_t *statusCodePtr)
 Get the HTTP status code from HTTP request.

Detailed Description

HTTP methods.


Function Documentation

WiconnectResult httpAddHeader ( WiconnectSocket socket,
const char *  key,
const char *  value 
) [inherited]

Add HTTP header key/value pair to opened HTTP request.

To use this function, the supplied WiconnectSocket parameter must have been created using either httpGet() or httpPost() and the 'openOnly' parameter TRUE.

This will add additional header to the HTTP request.

Use httpGetStatus() to issue the request.

Parameters:
[in]socketOpened socket to add additonal HTTP header
[in]keyHeader key (e.g. 'content-type')
[in]valueHeader value (e.g. 'application/json')
Returns:
Result of method. See WiconnectResult
WiconnectResult httpConnect ( WiconnectSocket socket,
const char *  url,
const HttpSocketArgs args 
) [inherited]

Connect to remote HTTP server.

This is the base method for the other HTTP methods.

Secure HTTP

Each HTTP method is able to connect to a secure HTTP server. To do this, the URL string parameter must start with 'https://' To connect to a secure HTTP server a TLS certificate is needed. The certificate is specified in the certFilename parameter of the method (or HttpSocketArgs parameter). This is the filename of an existing certificate on the module file system.

Note:
If the URL starts with 'https://' and no certificate filename is specified, the module's default certificate is used.
Parameters:
[out]socketHTTP WiconnectSocket object of opened connection.
[in]urlURL of HTTP request
[in]argsConfiguration HttpSocketArgs for HTTP connection
Returns:
Result of method. See WiconnectResult
WiconnectResult httpGet ( WiconnectSocket socket,
const char *  url,
bool  openOnly = false,
const char *  certFilename = NULL 
) [inherited]

Issue HTTP GET Request.

This method has the open to only 'open' the connection (disabled by default). This means a connection to the remote HTTP server is opened, but the HTTP request isn't issued. This allow for addition data to be added to the request. For instance, use httpAddHeader() to add additional headers to the request. Use httpGetStatus() to issue the HTTP request and receive the HTTP response.

Parameters:
[out]socketHTTP WiconnectSocket object of opened connection.
[in]urlURL of HTTP GET request
[in]openOnlyOptional, if TRUE this will only open a connection to the server (it won't issue the request)
[in]certFilenameOptional, filename of existing TLS certificate on module's file system. See Secure HTTP
Returns:
Result of method. See WiconnectResult
WiconnectResult httpGetStatus ( WiconnectSocket socket,
uint32_t *  statusCodePtr 
) [inherited]

Get the HTTP status code from HTTP request.

This may be used to either issue an HTTP request of an opened HTTP connection or return the status code of a request already issued.

Parameters:
[in]socketOpened socket to get http response status code
[out]statusCodePtrPointer to uint32 to hold http status code
Returns:
Result of method. See WiconnectResult
WiconnectResult httpHead ( WiconnectSocket socket,
const char *  url,
const char *  certFilename = NULL 
) [inherited]

Issue HTTP HEAD Request.

Parameters:
[out]socketHTTP WiconnectSocket object of opened connection.
[in]urlURL of HTTP HEAD request
[in]certFilenameOptional, filename of existing TLS certificate on module's file system. See Secure HTTP
Returns:
Result of method. See WiconnectResult
WiconnectResult httpPost ( WiconnectSocket socket,
const char *  url,
const char *  contextType,
bool  openOnly = true,
const char *  certFilename = NULL 
) [inherited]

Issue HTTP POST Request.

This method has the open to only 'open' the connection which enabled by default. This means a connection to the remote HTTP server is opened, but the HTTP request isn't issued. This allow for addition data to be added to the request. Use the returned WiconnectSocket object's 'write' methods to add POST data to the request. When all POST data has been written, use httpGetStatus() to issue the HTTP request and receive the HTTP response.

Parameters:
[out]socketHTTP WiconnectSocket object of opened connection.
[in]urlURL of HTTP POST request
[in]contextTypeThe value to go into the 'content-type' HTTP header (e.g. 'application/json')
[in]openOnlyOptional, if FALSE this will immediately issue the POST request.
[in]certFilenameOptional, filename of existing TLS certificate on module's file system. See Secure HTTP
Returns:
Result of method. See WiconnectResult