This tutorial demonstrates how to install and compile the BearHttpsClient library using precompiled files.
Download the precompiled library files to your project directory:
Using curl:
curl -L https://github.com/OUIsolutions/BearHttpsClient/releases/download/0.9.0/BearHttpsClient.c -o BearHttpsClient.c
curl -L https://github.com/OUIsolutions/BearHttpsClient/releases/download/0.9.0/BearHttpsClient.h -o BearHttpsClient.hCreate a file named main.c with the following content:
#include "BearHttpsClient.h"
int main(){
BearHttpsRequest *request = newBearHttpsRequest("https://example.com");
BearHttpsResponse *response = BearHttpsRequest_fetch(request);
if(BearHttpsResponse_error(response)){
printf("Error: %s\n",BearHttpsResponse_get_error_msg(response));
BearHttpsRequest_free(request);
BearHttpsResponse_free(response);
return 1;
}
const char *body = BearHttpsResponse_read_body_str(response);
if(BearHttpsResponse_error(response)){
printf("Error: %s\n",BearHttpsResponse_get_error_msg(response));
BearHttpsRequest_free(request);
BearHttpsResponse_free(response);
return 1;
}
printf("Body: %s\n",body);
BearHttpsRequest_free(request);
BearHttpsResponse_free(response);
return 0;
}Project directory structure:
BearHttpsClient.c
BearHttpsClient.h
main.c
GCC Compiler:
gcc -c BearHttpsClient.c -o BearHttpsClient.o
gcc main.c BearHttpsClient.o -o main
./mainClang Compiler:
clang -c BearHttpsClient.c -o BearHttpsClient.o
clang main.c BearHttpsClient.o -o main
./mainMicrosoft Visual C++ Compiler:
cl BearHttpsClient.c /c
cl main.c BearHttpsClient.obj /Fe:main.exe
main.exeMinGW Cross-Compiler:
i686-w64-mingw32-gcc -c BearHttpsClient.c -o BearHttpsClient.o
i686-w64-mingw32-gcc main.c BearHttpsClient.o -o main.exe -lws2_32
./main.exe