HTTP

From openPicus Wiki
Jump to: navigation, search

Contents

Introduction

HTTP is a communication protocol that uses TCP as the transport layer.

ATTENTION: the functions in this library are blockers for the FlyportTask

DOWNLOAD

Version

V.2.0

  • now it's only for Flyport PRO
  • new HTTP_Read
  • new ARRAY_SIZE(x) -> now is (sizeof(x)-1)
  • add #define HTTP_MAX_SIZE (default 5000)

V.1.2

  • add HTTP_Put

V.1.1

  • change syntax: now -> HTTP_Method, before -> HTTP_METHOD

V.1.0
This library is going to be constantly updated according to the feedback

Lastest library revision can be downloaded here


API List

HTTP_Get

Function to send a GET request and to receive the response
returns the HTTP code or 0 for timeout

int HTTP_Get(TCP_SOCKET socket, char * host, char * path_data, char * custom_header, char * header, int headersize, char * body, int bodysize, int timeout)
Argument Description
TCP_SOCKET socket the handle of the socket to use
char * host string with the host (server)
char * path_data string with the path (of file) and data, e.g. "/index.php?param1=val1"
char * custom_header string with custom headers (must include "\r\n", null header = "")
char * header pointer in which to store the header response
int headersize length of the header array (use ARRAY_SIZE(header))
char * body pointer in which to store the body response
int bodysize length of the body array (use ARRAY_SIZE(body))
int timeout timeout period in 10ms

HTTP_GetSimple

Function to send a GET request in easy way (minimal header and fixed timeout(2s)) and to receive the response
returns the HTTP code or 0 for timeout

int HTTP_GetSimple(TCP_SOCKET socket, char * host, char * path_data, char * header, int headersize, char * body, int bodysize)
Argument Description
TCP_SOCKET socket the handle of the socket to use
char * host string with the host (server)
char * path_data string with the path (of file) and data, e.g. "/index.php?param1=val1"
char * header pointer in which to store the header response
int headersize length of the header array (use ARRAY_SIZE(header))
char * body pointer in which to store the body response
int bodysize length of the body array (use ARRAY_SIZE(body))

HTTP_Post

Function to send a POST request and to receive the response
returns the HTTP code or 0 for timeout

int HTTP_Post(TCP_SOCKET socket, char * host, char * path, char * custom_header, char * CType, char * data, char * header, int headersize, char * body, int bodysize, int timeout)
Argument Description
TCP_SOCKET socket the handle of the socket to use
char * host string with the host (server)
char * path string with the path (of file), e.g. "/index.php"
char * custom_header string with custom headers (must include "\r\n", null header = "")
char * CType string with the Content-Type header, e.g. "application/x-www-form-urlencoded"
char * data string with the data, e.g. "param1=val1&param2=val2"
char * header pointer in which to store the header response
int headersize length of the header array (use ARRAY_SIZE(header))
char * body pointer in which to store the body response
int bodysize length of the body array (use ARRAY_SIZE(body))
int timeout timeout period in 10ms

HTTP_PostSimple

Function to send a POST request in easy way (minimal header, Content-Type: application/x-www-form-urlencoded and fixed timeout(2s)) and to receive the response
returns the HTTP code or 0 for timeout

int HTTP_PostSimple(TCP_SOCKET socket, char * host, char * path, char * data, char * header, int headersize, char * body, int bodysize)
Argument Description
TCP_SOCKET socket the handle of the socket to use
char * host string with the host (server)
char * path string with the path (of file), e.g. "/index.php"
char * data string with the data, e.g. "param1=val1&param2=val2"
char * header pointer in which to store the header response
int headersize length of the header array (use ARRAY_SIZE(header))
char * body pointer in which to store the body response
int bodysize length of the body array (use ARRAY_SIZE(body))

HTTP_Put

Function to send a PUT request and to receive the response
returns the HTTP code or 0 for timeout

int HTTP_Put(TCP_SOCKET socket, char * host, char * path, char * custom_header, char * data, char * header, int headersize, char * body, int bodysize, int timeout)
Argument Description
TCP_SOCKET socket the handle of the socket to use
char * host string with the host (server)
char * path string with the path (of file), e.g. "/index.php"
char * custom_header string with custom headers (must include "\r\n", null header = "")
char * data string with the data, e.g. "param1=val1&param2=val2"
char * header pointer in which to store the header response
int headersize length of the header array (use ARRAY_SIZE(header))
char * body pointer in which to store the body response
int bodysize length of the body array (use ARRAY_SIZE(body))
int timeout timeout period in 10ms

HTTP_URLEncode

Function to encode a string in a URL string

VOID HTTP_URLEncode(char * dest, char * src)
Argument Description
char * dest pointer in which to store the URL string
char * src string with the text to convert

HTTP_URLEncodeLen

Function to calculate the length of the future URL string
returns the length of the future URL string

int HTTP_URLEncodeLen(char * str)
Argument Description
char * str string with the text to calculate

HTTP_URLDecode

Function to decode a string in a no-URL string

VOID HTTP_URLDecode(char * dest, char * src)
Argument Description
char * dest pointer in which to store the no-URL string
char * src string with the text to convert

HTTP_URLDecodeLen

Function to calculate the length of the future no-URL string
returns the length of the future no-URL string

int HTTP_URLDecodeLen(char * str)
Argument Description
char * str string with the text to calculate
Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox