CURL is a simple example of returning "CURLE_WRITE_ERROR"

I am trying to run a simple example using libcurl, but just running this simple example gives me CURLE_WRITE_ERROR when running the curl_easy_perform(...) command. Does anyone know what I'm doing wrong? I 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); } 
+4
source share
1 answer

OK, it turns out that Joachim is right. I really 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); } 
+3
source

All Articles