tags:

views:

33

answers:

1

hello, 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;
}
+2  A: 

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)
{
}

and calling

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);

Should do it.

Ashaman