HTTP Client

Application can create HTTP client, send HTTP request, receive HTTP response or close the HTTP session.

Libre_IoNewHttpClient

Libre_IoNewHttpClient(host, port, https, method, uri, headers, body)

Start a HTTP client.

Parameters:

  • host - String, the string representation of IP or host name.
  • port - Integer, the TCP port.
  • https - Boolean, true for HTTPS connection; false for HTTP.
  • method - String representing HTTP method, for example, GET, POST, PUT etc.
  • url - String, the request Uri.
  • headers - Table of headers as key/value pairs.
  • body - The data to be posted, can be nil.

Returns:

  • The socket handle.

Note: The returned socket handle shall be used in HTTP read/write and close; as well as event subscription.

Note: Connecting to external host is highly regulated by our privacy policy. Applications from our App Store must follow our privacy guideline in order to get approved. External host is allowed on “whitelist” basis per application and specific hosts.

Libre_IoGetHttpResponse

Libre_IoGetHttpResponse(fd)

Get response from HTTP(S) client.

Parameters:

  • fd - The socket handle.

Returns:

  • ok - Boolean, true if no error; otherwise false.
  • result - Nil if still reading response (ok=true); a table if response has been retrived successfully.
    • version - HTTP version string.
    • code - HTTP response code string.
    • status - HTTP response status string.
    • headers - HTTP response headers. This object is table of key/value pairs.
    • body - HTTP response body string. It could be string of binary data.