Skip to content

MTY_HttpRequest

chrisd1100 edited this page May 13, 2023 · 2 revisions

Make a synchronous HTTP request.

Only Content-Encoding: gzip is supported for compression.

bool MTY_HttpRequest(
    const char * url,
    const char * method,
    const char * headers,
    const void * body,
    size_t       bodySize,
    const char * proxy,
    uint32_t     timeout,
    void **      response,
    size_t *     responseSize,
    uint16_t *   status
);

Parameters

url (const char *)

The URL for the request, the scheme must be either http or https.

method (const char *)

The HTTP method, i.e. GET or POST.

headers (const char *)

HTTP header key/value pairs in the format Key:Value separated by newline characters.

May be NULL for no additional headers.

body (const void *)

Request payload.

bodySize (size_t)

Size in bytes of body.

proxy (const char *)

The proxy URL including the port, i.e. http://example.com:1337, or NULL to use the OS's default proxy.

timeout (uint32_t)

Time to wait in milliseconds for completion.

response (void **)

Set to the response body, or NULL if there is no response body.

responseSize (size_t *)

Set to the size of response, or 0 if there is no response body.

status (uint16_t *)

The HTTP response status code.

Return value

bool

Returns true on success, false on failure. Call MTY_GetLog for details.

If successful, response is dynamically allocated and must be destroyed with MTY_Free.

Platform support

Windows   macOS   Android   Linux   Web  

See also

Module: Net

Clone this wiki locally