#include <iostream>
#include <string>
#include <curl/curl.h>
using namespace std;
size_t write_html(void *ptr, size_t size, size_t count, void *stream) {
( (string*)stream )->append( (char*)ptr, 0, size*count);
return size * count;
}
bool http_get(char *url, string &html) {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if( curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
res = curl_easy_perform(curl);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_html);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &html);
curl_easy_cleanup(curl);
return true;
} else {
return false;
}
}
int main(int argc, char* argv[] )
{
string html;
if(http_get("http://www.google.com", html))
cout << html << endl;
return 0;
}
카테고리 없음