I am trying to run a simple example using libcurl, but just running this simple example gives me CURLE_WRITE_ERROR when I execute the curl_easy_perform(...) command. Does anyone have any idea what I am doing wrong? I have also tried other sites besides example.com.
CURL *curl = curl_easy_init();
if(curl) 
{
    CURLcode res;
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/");
    res = curl_easy_perform(curl); // returns CURLE_WRITE_ERROR always!
    curl_easy_cleanup(curl);
}
                OK turns out Joachim is right. I did need a write callback
size_t CurlWriteCallback(char* buf, size_t size, size_t nmemb, void* up)
{ 
    TRACE("CURL - Response received:\n%s", buf);
    TRACE("CURL - Response handled %d bytes:\n%s", size*nmemb);
    // tell curl how many bytes we handled
    return size*nmemb;
}
// ...
CURL *curl = curl_easy_init();
if(curl) 
{
    CURLcode res;
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &CurlWriteCallback);
    curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/");
    res = curl_easy_perform(curl); 
    curl_easy_cleanup(curl);
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With