cURL / Mailing Lists / curl-library / Single Mail


Compiling libcurl for https

From: Andrew Williams <>
Date: Wed, 21 Oct 2015 12:08:40 +1100

First post and a novice developer although I have spent the best part of
25 years hacking at various languages.

I'm using VS Community 2015 as an IDE.

I'm trying to evaluate libcurl as a library for use in another desktop

I managed to get some example code working after compiling libcurl. I
got all those symbol errors if I just tried to use the pre-compiled

The application even worked for HTTP source images.

When I tried it with the target URL with HTTPS it failed.

I did a curl.exe -V and https isn't listed as a supported source
although I'm not sure it supposed to. In some systems http implies https.

So my code works for HTTP but here it is just to make sure.
My question is do I need to do anything special to get libcurl to
support https or is there something else in the code that's missing?

#include "stdafx.h"
#include <stdio.h>
#include <curl\curl.h>

size_t callbackfunction(void *ptr, size_t size, size_t nmemb, void*
     FILE* stream = (FILE*)userdata;
     if (!stream)
         printf("!!! No stream\n");
         return 0;

     size_t written = fwrite((FILE*)ptr, size, nmemb, stream);
     return written;

bool download_jpeg(char* url)
     FILE* fp = fopen("out.jpg", "wb");
     if (!fp)
         printf("!!! Failed to create file on the disk\n");
         return false;

     CURL* curlCtx = curl_easy_init();
     curl_easy_setopt(curlCtx, CURLOPT_URL, url);
     curl_easy_setopt(curlCtx, CURLOPT_WRITEDATA, fp);
     curl_easy_setopt(curlCtx, CURLOPT_WRITEFUNCTION, callbackfunction);
     curl_easy_setopt(curlCtx, CURLOPT_FOLLOWLOCATION, 1);

     CURLcode rc = curl_easy_perform(curlCtx);
     if (rc)
         printf("!!! Failed to download: %s\n", url);
         return false;

     long res_code = 0;
     curl_easy_getinfo(curlCtx, CURLINFO_RESPONSE_CODE, &res_code);
     if (!((res_code == 200 || res_code == 201) && rc !=
         printf("!!! Response code: %d\n", res_code);
         return false;



     return true;

int main(int argc, char** argv)
     if (argc < 2)
         printf("Usage: %s <url>\n", argv[0]);
         return -1;

     if (!download_jpeg(argv[1]))
         printf("!! Failed to download file: %s\n", argv[1]);
         return -1;

     return 0;
List admin:
Received on 2015-10-21