cURL / Mailing Lists / curl-library / Single Mail

curl-library

HTTP Post with json body and client SSL certificate validation

From: Victor Dodon <dodonvictor_at_gmail.com>
Date: Fri, 27 Sep 2013 14:28:29 +0300

Hello all!

I am working on a server that needs to do some push notifications for
devices with Android, iOS and Window Phone and it's the first time I use
libcurl. I know that the api reference can be found at [1], but I will ask
a few questions that I have not found answers in the api reference.

Q1. I need to set some custom headers for each request. The list of custom
headers can be freed imediately after curl_easy_setopt(curl,
CURLOPT_HTTPHEADER, slist) or only after the curl_easy_perform has returned?

Q2. How to do a post request with json HTTP body? Is something like this:

char *post_body = json_dumps(json, 0);
struct curl_slist *slist=NULL;
slist = curl_slist_append(slist, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_body);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(post_body);

?

Q3. Microsoft and Apple server require client SSL certificate validation.
Assuming that I have a suitable SSL certififcate, what options I need to
set on curl handles to achieve this? CURLOPT_SSLCERT
and CURLOPT_SSLCERTTYPE are enough?

Thank you very much!
Victor Dodon.

[1] http://curl.haxx.se/libcurl/c/

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-09-27