Skip to content

CALL_HTTP

Jurek Muszyński edited this page Mar 31, 2022 · 6 revisions

bool CALL_HTTP(void *req, void *res, const char *method, const char *url, bool keep)

Description

Makes HTTP request. req and res are plain char* pointers. CALL_HTTP can block for up to callHTTPTimeout milliseconds. If not set, CALL_HTTP_DEFAULT_TIMEOUT is used, which is currently 10000 ms.

keep is for keeping connection open after request. When no longer needed, it can be closed with CALL_HTTP_DISCONNECT.

For more information see RESTful calls from Node++.

Returns

true if the full response content was read successfully, otherwise false. res will contain a NULL-terminated string with response body.

Example

CALL_HTTP_HEADERS_RESET;

CALL_HTTP_HEADER_SET("apiConsumerId", "123456789");
CALL_HTTP_HEADER_SET("Authorization", "Bearer v2-6998a852-1521-4745-a1f3-e55341092e9f");

char req[]="";
char res[CALL_HTTP_MAX_RESPONSE_LEN];

if ( !CALL_HTTP(req, res, "GET", "example.com:8888/api/v1.0/accounts/v1.0/getAccount", false) )
{
    // TCP level error, i.e. couldn't connect to the remote host
    ERR("Couldn't connect to example.com");
    OUT("<p>Couldn't connect to example.com</p>");
    return ERR_REMOTE_CALL;
}
else if ( !CALL_HTTP_STATUS_OK )
{
    // HTTP level error
    WAR("getAccount status %d", CALL_HTTP_STATUS);
    OUT("<p>%s</p>", res);
    return ERR_REMOTE_CALL_STATUS;
}

// OK

OUT("<p>Got response:</p>");
OUT("<p>%s</p>", res);

Clone this wiki locally