Creates a resource that defines the content of the HTTP request and returns an HTTP request handle that represents it.

Syntax

HTTP_REQUEST_HANDLE HTTP_CreateRequest(
  char *targetURL,
  char cMethod,
  char *uploadData,
  size_t uploadSize,
  char *extraHeader,
  unsigned int timeout,
  unsigned int option
);

Parameters

targetURL
[in] Specify the server URL. You can include the port number and query parameters in this parameter.
cMethod
[in] Specifies the method of the HTTP request with one of the following values.
Value Description
HTTP_REQ_GET GET method
HTTP_REQ_POST POST method
uploadData
[in] Specifies a pointer to the buffer for send data. Specify NULL if there is no data to send.
uploadSize
[in] Specifies the length of send data. Specify 0 if there is no data to send.
extraHeader
[in] You can specify additional HTTP request headers. You can add multiple lines of request headers, but be sure to add CrLf to the end of each header line.

The following header will be added automatically.

For GET method: Host header is automatically added.
For POST method: Host header and Content-Length header are automatically added.

Specify NULL if there are no additional headers.

timeout
[in] Specifies the timeout period for waiting for a response in milliseconds.
option
[in] You can specify the following option flag. Set 0 if no option is required.
Value Description
HTTP_FLAG_BYPASSMODE Allow an opened SSL socket to bypass the X509 certificate verification process.

Return value

Returns the HTTP request handle if the function succeeds, NULL otherwise.

Remarks

Creates a resource that defines an HTTP request according to the parameters, and returns an HTTP request handle that represents this.

Specify the HTTP request handle obtained by this function and call the HTTP_GetResponse function to send the HTTP request and receive the HTTP response.

If the HTTP request handle returned by this function is other than NULL, be sure to call HTTP_CloseRequest function to release the HTTP request resources.

Requirements

Header file:
lib.h
http_request.h
Library file:
libHttpRequest.a
libSTARTUPOPH5000.a

Sample

Sample
#define SERVER_URL      "http://192.168.1.10:8080"
#define SERVER_RESPONSE_TIMEOUT     (15000/20)
#define HTTP_OPTION     0
...
    char* postData;
...
    hRequest = HTTP_CreateRequest(
        SERVER_URL,
        HTTP_REQ_POST,
        postData,
        strlen(postData),
        "Content-Type: application/json\r\nConnection: close\r\n",
        SERVER_RESPONSE_TIMEOUT,
        HTTP_OPTION);
...



Last updated: 2021/11/19