cURL / Mailing Lists / curl-users / Single Mail


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

From: Pankaj Kumar Maharana <>
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,
curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH,

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,

List admin:
Received on 2009-03-30