i got a small program from http://curl.haxx.se/ and while i run it always prints the webpage how can i disable the printing function
#include <iostream>
#include <curl/curl.h>
using namespace std;
int main() {
    CURL *curl;
      CURLcode res;
      curl = curl_easy_init();
      if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION,1);
        res = curl_easy_perform(curl);
        /* always cleanup */
        curl_easy_cleanup(curl);
      }
      return 0;
}
                You need to set up a CURLOPT_WRITEFUNCTION to make it not use stdout.
There is an explanation here (under CURLOPT_WRITEFUNCTION): http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
and here (Under "Handling the Easy libcurl): http://curl.haxx.se/libcurl/c/libcurl-tutorial.html
Basically adding the function:
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp)
{
   return size * nmemb;
}
and calling
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
Should do it.
You can still get diagnostic messages. To stop these either change or add the following line:
curl_easy_setopt (curl, CURLOPT_VERBOSE, 0L); //0 disable messages
                        To write data into file instead of printing, give a file descriptor as:
FILE *wfd = fopen("foo.txt", "w");
...
curl_easy_setopt(curl, CURLOPT_WRITEDATA, wfd);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
                        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