cURL / Mailing Lists / curl-library / Single Mail


Re: libcurl and ssl/tls/https

From: Marco Maggi <>
Date: Mon, 21 Dec 2009 21:18:14 +0100

"Joshua McCracken" wrote:
> I've been looking for some docs on using Transport Layer
> Security and it's predecessors in conjunction with
> libcurl. [...] All I need to do is write it to make a
> https post request to a url specified by the user in a
> command line argument. I've already taken care of
> everything else, and tested it thoroughly.

The following program will connect to "" and
download the default page; it prints the page on "stderr".
As you can see it is a very simple program, which makes no
use of client certificate; start from it and try to add the
options you need.


#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>

#define COK(CALL) \
  do { \
    e = (CALL); \
    if (CURLE_OK != e) { \
      fprintf(stderr, curl_easy_strerror(e)); \
      exit(EXIT_FAILURE); \
    } \
  } while (0)

cb (void * buffer, size_t item_size, size_t item_number, void * custom)
  fwrite(buffer, item_size, item_number, stderr);
  return (item_size * item_number);
main (int argc, const char *const argv[])
  CURL * handle = curl_easy_init();
  int e;
  COK(curl_easy_setopt(handle, CURLOPT_URL, ""));
  COK(curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, cb));
  COK(curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL));
  COK(curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0));

Marco Maggi
List admin:
Received on 2009-12-21