cURL / Mailing Lists / curl-users / Single Mail

curl-users

Error handling:-- Http-401: Unauthorized in CURL

From: Pankaj Kumar Maharana <maharana.pankaj_at_gmail.com>
Date: Mon, 30 Mar 2009 17:27:11 +0530

How to successfully handle Http error code 401(Unauthorized) in CURL.

In my programm, I am setting

curl_easy_setopt(curl__handle, CURLOPT_HEADERFUNCTION,
header_callback_function);
curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH,
CURLAUTH_BASIC|CURLAUTH_DIGEST);

What I found is if we do not set
curl_easy_setopt(curl_handle, CURLOPT_USERPWD, "_:_"); {Kind of dummy
username password} with the initial request, Than
header_callback_function() is not called by CURL for 401 error.

What I need is "header_callback_function()" should be called by CURL for 401
error. So that I can provide the proper username and password.

The problem with the above dummy kind of hack is that CURL is not taking the
proper username and password later when provided with the same handle.

Can somebody kindly help me in this regard?

Best Regards,
Paanky

-------------------------------------------------------------------
List admin: http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-03-30