A simple HTTPS client

To bring the concepts of this chapter together, we build a simple HTTPS client. This client can connect to a given HTTPS web server and request the root document /

Our program begins by including the needed chapter header, defining main(), and initializing Winsock as shown here:

/*https_simple.c*/#include "chap09.h"int main(int argc, char *argv[]) {#if defined(_WIN32)    WSADATA d;    if (WSAStartup(MAKEWORD(2, 2), &d)) {        fprintf(stderr, "Failed to initialize.\n");        return 1;    }#endif

We then initialize the OpenSSL library with the following code:

   /*https_simple.c continued*/    SSL_library_init();    OpenSSL_add_all_algorithms();    SSL_load_error_strings();

The SSL_load_error_strings() function call is optional, but it's very useful ...

Get Hands-On Network Programming with C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.