curl-users
Writing cURL response to a file or a string in C++
Date: Mon, 4 Mar 2013 06:33:31 -0800
Hello All,
I am trying to run cURL to a PHP URL and get back a response and write it
to a file or first a string, then a file, which ever works best.
OSX 10.8, latest cURL.
I have:
CURL* curl;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, jstr.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);
curl_easy_perform(curl);
std::ofstream outFile;
outFile.open(lFileName.c_str());
if (outFile.good())
{
outFile << stream.str();
}
outFile.close();
curl_easy_cleanup(curl);
curl_global_cleanup();
the write_data():
size_t write_data(char *ptr, size_t size, size_t nmemb, void *userdata)
{
std::ostringstream *stream = (std::ostringstream*)userdata;
size_t count = size * nmemb;
stream->write(ptr, count);
return count;
}
I seem to be crashing at: stream->write(ptr, count);
with simply a bus error
the url is correct and if I paste the url into a browser it does return the
string
Any pointers would be appreciated.
-------------------------------------------------------------------
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 2013-03-04