2010年2月24日

curl easy perform with proxy

// test_curl.c
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <curl/easy.h>

int url_Perform(CURL* url, char* url_str) {
curl_easy_setopt(url, CURLOPT_URL, url_str);
CURLcode code = code = curl_easy_perform(url);
if(code != CURLE_OK) {
printf("%s\n", curl_easy_strerror(code));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

int main(int argc, char* argv[]) {
CURL* url = curl_easy_init();
char* proxy = getenv("http_proxy");
curl_easy_setopt(url, CURLOPT_PROXY, proxy);
int code = url_Perform(url, argv[1]);
curl_easy_cleanup(url);
return code;
}
/*
$ gcc -lcurl -o test_curl test_curl.c;http_proxy=http://proxy:3128 ./test_curl http://www.google.com
*/

沒有留言:

網誌存檔