Created
July 12, 2015 05:50
-
-
Save gcphost/3f3c46f15e4e86c58bff to your computer and use it in GitHub Desktop.
CPP Curl Retrieve Website
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <curl/curl.h> | |
using namespace std; | |
string contents=""; | |
string check_url(string url){ | |
string results=""; | |
curl_global_init(CURL_GLOBAL_SSL ); | |
CURL* curl = curl_easy_init(); | |
if(curl) { | |
curl_easy_setopt (curl,CURLOPT_SSL_VERIFYHOST, 0L); | |
curl_easy_setopt (curl,CURLOPT_SSL_VERIFYPEER, 0L); | |
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); | |
curl_easy_setopt(curl,CURLOPT_URL, url.c_str()); | |
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,handle_data); | |
CURLcode res = curl_easy_perform(curl); | |
curl_easy_cleanup(curl); | |
curl_global_cleanup(); | |
if(res != CURLE_OK){ | |
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); | |
} | |
if (res == 0){ | |
if(iequals(contents, string(""))){ | |
results=""; | |
} else results=contents; | |
} | |
} | |
contents=""; | |
return results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment