cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: libcurl and ssl/tls/https

From: Marco Maggi <marco.maggi-ipsu_at_poste.it>
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 "https://gna.org/" 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.

HTH

#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)

size_t
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);
}
int
main (int argc, const char *const argv[])
{
  CURL * handle = curl_easy_init();
  int e;
  COK(curl_easy_setopt(handle, CURLOPT_URL, "https://gna.org/"));
  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));
  COK(curl_easy_perform(handle));
  exit(EXIT_SUCCESS);
}

-- 
Marco Maggi
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2009-12-21