cURL / Mailing Lists / curl-users / Single Mail

curl-users

Proxy fail: Failure when receiving data from the peer.

From: »ÆÐÄâù <e_balloon_at_163.com>
Date: Thu, 30 Aug 2012 15:16:53 +0800 (CST)

 hi,
  I am trying to send a request to a website through proxy by libcurl.
  I can successfully visite the website by set the same proxy to IE web browser.
  But fail by libcurl with error message:Failure when receiving data from the peer.
  Here is the curl log:

* About to connect() to proxy 9.119.41.121 port 8080 (#0)
* Trying 9.119.41.121... * connected
* Connected to 9.119.41.121 (9.119.41.121) port 8080 (#0)
* Establish HTTP proxy tunnel to wwwbeta-sso.toronto.ca.ibm.com:444
* Proxy auth using Basic with user 'username'
> CONNECT wwwbeta-sso.toronto.ca.ibm.com:444 HTTP/1.1
Host: wwwbeta-sso.toronto.ca.ibm.com:444
Proxy-Authorization: Basic dXNlcm5hbWU6cGFzc3cwcmQ=
Proxy-Connection: Keep-Alive

< HTTP/1.1 403 Forbidden
< Date: Thu, 30 Aug 2012 06:43:36 GMT
< Content-Length: 235
< Content-Type: text/html; charset=iso-8859-1
<
* Received HTTP code 403 from proxy after CONNECT
* Closing connection #0

 I am not sure what is happening here. Here is my source code. I Hope u can help, thanks!

    curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error);
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    curl_easy_setopt(curl, CURLOPT_URL, m_curUrl.c_str());

    //set curl to automatically locate
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);

    //set max number to follow location
    curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 255);

    //send POST request always, as if follow rfc, the locate request might be a GET
    curl_easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL);

    //no custom header
    curl_easy_setopt(curl, CURLOPT_HEADER, 0);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);

    m_replyMsg = "";
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &m_replyMsg);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecallback);

    //coockie file
    curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "tmp_cookie.cookie");
   
    //set proxy
    curl_easy_setopt(curl, CURLOPT_PROXY, m_proxyServer.c_str());
    curl_easy_setopt(curl,CURLOPT_PROXYUSERPWD, m_proxyId.c_str());

    // send user and password information to location hosts
    curl_easy_setopt(curl, CURLOPT_UNRESTRICTED_AUTH, 1L);

    std::string postField = "userid=";
    postField += f_userid;
    postField += "&pw=";
    postField += f_pw;
    postField += "&submit=";
    postField += "Generate key";
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postField.c_str());
    curl_easy_setopt(curl, CURLOPT_POST, -1);

    CURLcode curlRet = curl_easy_perform(curl);

Besides, if I remove the two line to set proxy, and run this in a enviroment that doesn't need proxy, this works fine.

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-08-30