Skip to content

CF_HttpsRequest

Category: web
GitHub: cute_https.h


Represents an HTTPS request.

Code Example

Creating a request and waiting for a response.

int main(int argc, char argv[])
{
    const char hostname = "www.google.com";
    //const char hostname = "badssl.com";
    //const char hostname = "expired.badssl.com";
    //const char hostname = "wrong.host.badssl.com";
    //const char hostname = "self-signed.badssl.com";
    //const char hostname = "untrusted-root.badssl.com";
    CF_HttpsRequest request = cf_https_get(hostname, 443, "/", true);

    while (1) {
        CF_HttpsResult state = cf_https_process(request);
        if (state < 0) {
            printf("%s\n", cf_https_result_to_string(state));
            cf_https_destroy(request);
            return -1;
        }
        if (state == CF_HTTPS_RESULT_OK) {
            break;
        }
    }

    CF_HttpsResponse response = cf_https_response(request);
    const char content = cf_https_response_content(response);
    int length = cf_https_response_content_length(response);
    printf("%.s", length, content);
    cf_https_destroy(request);

    return 0;
}

Remarks

You may create a request by calling either cf_https_get or cf_https_post. It is intended to continually call cf_https_process in a loop until the request generates a response, or fails.

cf_https_post
CF_HttpsResponse
cf_https_get