curl-library
HTTP proxy issue
Date: Fri, 27 Apr 2012 20:43:47 +0800
Daniel et all,
I'm using libcurl 7.22.0, but something troubles me.
I'v written the following codes in hope of making a HTTP request through a HTTP proxy (hosted by CCProxy: www.ccproxy.com/).
void ConfigProxy(CURL *easy_handle, const Proxy& proxy)
{
if (proxy.type == ProxyNone)
return;
curl_easy_setopt(easy_handle, CURLOPT_PROXYTYPE, proxy.type);
curl_easy_setopt(easy_handle, CURLOPT_PROXY, proxy.host.c_str());
curl_easy_setopt(easy_handle, CURLOPT_PROXYPORT, proxy.port);
if (!proxy.user.empty())
{
curl_easy_setopt(easy_handle, CURLOPT_PROXYUSERNAME, proxy.user.c_str());
if (!proxy.pass.empty())
curl_easy_setopt(easy_handle, CURLOPT_PROXYPASSWORD, proxy.pass.c_str());
}
}
void MyCurl::DoRequest()
{
#ifndef NDEBUG
curl_easy_setopt(easy_handle_, CURLOPT_VERBOSE, 1);
#endif
curl_easy_setopt(easy_handle_, CURLOPT_ERRORBUFFER, error_buffer_);
curl_easy_setopt(easy_handle_, CURLOPT_URL, url_.c_str());
curl_easy_setopt(easy_handle_, CURLOPT_HTTPHEADER, header_list_);
curl_easy_setopt(easy_handle_, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(easy_handle_, CURLOPT_COOKIEFILE, ""); // enable cookie
if (!post_)
curl_easy_setopt(easy_handle_, CURLOPT_POST, 0);
else
{
curl_easy_setopt(easy_handle_, CURLOPT_POST, 1);
if (form_post_ != NULL)
{
curl_easy_setopt(easy_handle_, CURLOPT_HTTPPOST, form_post_);
// we have some files to upload
if (!upload_file_handles_.empty())
curl_easy_setopt(easy_handle_, CURLOPT_READFUNCTION, ReadOSFile);
}
}
ConfigProxy(easy_handle_, proxy_);
....... perform operations here .........
}
But, it does not work as i expected. It sends "GET some_url HTTP/1.1" instead of "CONNECT some_host HTTP/1.1".
libcurl sent:
GET http://www.google.com HTTP/1.1
Proxy-Authorization: Basic password_in_base64
User-Agent: curl/7.22.0 (i386-pc-win32) libcurl/7.22.0
Host: 163.com
Accept: */*
Proxy-Connection: Keep-Alive
rather than:
CONNECT 192.168.144.4:443 HTTP/1.1
Proxy-Authorization: Basic password_in_base64
Proxy-Connection: Keep-Alive
Accept: */*
Content-Type: text/html
Content-length: 0
And then, Google's sorry page is recieved, because CCProxy forwards my request as:
GET HTTP/1.1
Host: www.google.com
Accept: */*
Connection: Keep-Alive
User-Agent: curl/7.22.0 (i386-pc-win32) libcurl/7.22.0
How can i solve this problem? Please help me.
Btw, if i don't use proxy, it works well.
Best regards,
Kenneth
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-04-27