cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to resend request when authentication

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 26 Dec 2013 22:44:57 +0100 (CET)

On Thu, 26 Dec 2013, lizhilong wrote:

> I'm working for basic authentication by curl.
> I set header callback as follow.
> curl_easy_setopt(d->m_handle, CURLOPT_HEADERFUNCTION, headerCallback);
>
> In headerCallback(),I set authentication message when catch 401 httpcode.
> String userpass = credential.user() + ":" + credential.password();
> curl_easy_setopt(d->m_handle, CURLOPT_USERPWD, userpass.utf8().data());
>
> In the run , I set wrong user and password for request. In expect
> headerCallback() will be called until I set right message . but actually ,It
> just call two times,then give me a wrong page.

libcurl will send the request as you ask it do, and the response is then a 401
with that "wrong page" contents.

What else could libcurl do?

> Does I need resend the request when I set authentication message?

Yes

> And How to resend the request?

After curl_easy_perform() has returned, you set the new options and you call
curl_easy_perform() again.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2013-12-26