Skip to content

Instantly share code, notes, and snippets.

@kunpengku
Created June 30, 2014 09:07
Show Gist options
  • Save kunpengku/5a9e3cbfa8314458ae6f to your computer and use it in GitHub Desktop.
Save kunpengku/5a9e3cbfa8314458ae6f to your computer and use it in GitHub Desktop.
c++ 里简单请求http
#include <iostream>
#include "curl/curl.h"
using namespace std;
int main()
{
CURL *_curl;
CURLcode _res;
const string urltmp("http://xxvity&usxxx=222");
cout << urltmp << endl;
FILE *fp_sohu = fopen("sohu.html", "ab+");
_curl = curl_easy_init();
curl_easy_setopt( _curl, CURLOPT_URL, urltmp.c_str() );
// curl_easy_setopt( _curl, CURLOPT_POSTFIELDS, _post_str.c_str() );
// curl_easy_setopt( _curl, CURLOPT_POST, 1 );
curl_easy_setopt( _curl, CURLOPT_HTTPGET, 1 );
curl_easy_setopt( _curl, CURLOPT_VERBOSE, 1 );
// curl_easy_setopt( _curl, CURLOPT_PORT, 8080 );
curl_easy_setopt( _curl, CURLOPT_TIMEOUT, 5 );
curl_easy_setopt( _curl, CURLOPT_CONNECTTIMEOUT, 1 );
curl_easy_setopt( _curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt( _curl, CURLOPT_HEADER, 1 );
curl_easy_setopt( _curl, CURLOPT_FOLLOWLOCATION, 1 );
curl_easy_setopt(_curl, CURLOPT_WRITEDATA, fp_sohu);
_res = curl_easy_perform( _curl );
return 0;
}
//g++ a.cpp -lcurl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment