cURL / Mailing Lists / curl-users / Single Mail

curl-users

Problem with CallBack function and HTTPS

From: Lennart Martens <len.martens_at_gmail.com>
Date: Tue, 22 May 2012 12:07:11 +0200

Hi all,

I'm using libcURL with SSL support to make some requests with HTTPS and get
an XML response (It's a C++ wrapper)
I add a callback function to catch the response:

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());

curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER, true);
curl_easy_setopt(curl, CURLOPT_CAINFO, "C:\\FULL-PATH\\cacert.pem");
//Adding the POST parameters
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);

curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,&CurlResponseData::Handle);
curl_easy_setopt(curl,CURLOPT_WRITEDATA,&f);
res = curl_easy_perform(curl);
if(res == CURLE_OK)
{

And this is (a piece of) my CallBack class:

/** Catches response of webservice.
* This class provides the callback function, needed for libcURL.
* The callback function catches the answer of the webservice.
*/
class CurlResponseData
{
public:
//CallBack function - Implementation as described in documentation of
libcURL
static size_t Handle(char* data, size_t size, size_t nmemb, void* p)
{
return static_cast<CurlResponseData*>(p)->HandleImpl(data, size, nmemb);
}
size_t HandleImpl(char* data, size_t size, size_t nmemb)
{
char* sizeData = data + std::strlen(data);
m_Content.insert(m_Content.end(), data, sizeData);
return size * nmemb;
}

private:
std::vector<char> m_Content;
};

This CallBack function works perfect with HTTP-requests. But my XML-parser
broke down with HTTPS-requests.
A short investigation learned that there's a trailing 0 at my reponse
in size_t HandleImpl(char* data, size_t size, size_t nmemb), which makes my
XML-response invalid.

Is there someone who knows where this 0 comes from?

Thanks,

Lennart

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-05-22