Advertisement
Benjamin_Loison

Curl test

Aug 24th, 2017
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <curl.h>
  3. using namespace std;
  4.  
  5. size_t writeCallback(void *contents, size_t size, size_t nmemb, void *userp)
  6. {
  7.     ((string*)userp)->append((char*)contents, size *nmemb);
  8.     return size *nmemb;
  9. }
  10.  
  11. int main(int argc, char** argv)
  12. {
  13.     CURL *curl = curl_easy_init();
  14.     string got;
  15.     curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.fr");
  16.     curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
  17.     curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
  18.     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
  19.     curl_easy_setopt(curl, CURLOPT_WRITEDATA, &got);
  20.     curl_easy_perform(curl);
  21.     curl_easy_cleanup(curl);
  22.     cout << "Source code of https://www.google.fr:" << endl << endl << got << endl;
  23.     while(1);
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement