cURL / Mailing Lists / curl-library / Single Mail

curl-library

[Q]: http proxy authorization using libcurl ?

From: <jskuo_at_cht.com.tw>
Date: Sat, 09 Aug 2003 19:28:13 +0800

Hi,

I'm a newbie to curl library.

I'm trying to use libcurl as a http client(GET).

My programming enviroment is: VC++ 6.0 SP5, stlport 4.5.3 on Windows
2000 SP3

The libcurl is a great tool and I compiled it into a dll(set "using
runtime library" to " using multithreaded dll") when linking with it.

It's also fine when I used the command-line version curl.exe in the dos-box.
I issues such a command in the dos-box and it's ok.
"curl --proxy 10.100.100.100:8080 --proxy-user user_abc:passwd_abc
--dump-header a.txt --verbose www.google.com"

It's fine when fetching pages in those sites behind my http proxy using
my program called libcurl directly.
However, when my program tried to access those pages outside of proxy,
some problems got, especially in proxy authorization.

One point should be pointed out here, I've wriiten my programs in c++
and STL.
"string" is a specialization of basic_string with char.

When I issue these instructions in my program, te libcurl returned a
code of 5 which means

"Couldn't resolve proxy. The given proxy host could not be resolved." found in
http://curl.haxx.se/libcurl/c/libcurl-errors.html

string szTmp1(szProxy_ + ":" + szPort_);
///case #1
//::curl_easy_setopt(hCurl_, CURLOPT_PROXY, szTmp1.c_str());

However, when I change the above code to the following
//case #2
::curl_easy_setopt(hCurl_, CURLOPT_PROXY, szProxy_.c_str());
long iPort = ::atol(szPort_.c_str());
::curl_easy_setopt(hCurl_, CURLOPT_PROXYPORT, iPort);
}

It did connect to proxy host and did proxy authorization.
It failed to authorize this action finally.

It seemed that I didn't submit correct username and password.

Is there anyone else who can help and give some suggestions ?

Best Regards,

James Kuo

//// a code snippet ///
::curl_easy_setopt(hCurl_, CURLOPT_NOSIGNAL, true);//for MT

::curl_easy_setopt(hCurl_, CURLOPT_FOLLOWLOCATION, 1);

::curl_easy_setopt(hCurl_, CURLOPT_URL, chUrl);//set url to get

::curl_easy_setopt(hCurl_, CURLOPT_VERBOSE, 1);

///proxy authorization
if (!szProxy_.empty() && !szPort_.empty()) {
string szTmp1(szProxy_ + ":" + szPort_);

///case #1
//::curl_easy_setopt(hCurl_, CURLOPT_PROXY, szTmp1.c_str());

//case #2
::curl_easy_setopt(hCurl_, CURLOPT_PROXY, szProxy_.c_str());
long iPort = ::atol(szPort_.c_str());
::curl_easy_setopt(hCurl_, CURLOPT_PROXYPORT, iPort);
}

if (!szUser_.empty() && !szPasswd_.empty()) {
string szTmp2(szUser_ + ":"+ szPasswd_);
cout << "username/password: " << szTmp2 << endl;
::curl_easy_setopt(hCurl_, CURLOPT_PROXYUSERPWD, szTmp2.c_str());//set
url to get
}

CURLcode res= ::curl_easy_perform(hCurl_);

cout << "returned code: " << res << endl;

-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
Received on 2003-08-09