cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: username+password

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 21 Jun 2002 12:05:49 +0200 (MET DST)

On Thu, 20 Jun 2002, Adrian Mardare wrote:

> I'm trying to use libcurl to get a file form a site that requires a
> username and a password. If I type the url in a browser ( like IE ), the IE
> knows to prompt me for the username + password. Shouldn't the curl library
> ( or the curl command line tool ) do the same thing ? It seems to me that
> CURLOPT_PASSWDFUNCTION callback should be invoked in this case and it
> should allow me to specify an username and a passwd. The curl library
> should be smart to detect when a authentication is required based on the
> url given and the response from server. How can this be done?

libcurl *could* very well be smart and discover this, but it doesn't. libcurl
gives you the freedom to do exactly what kind of requests you want. If you
want to request pages for which you don't have access to without a
username+password, then fine just go ahead.

The password request callback is only used for resources that *require*
passwords to work. Like if you use a certificate, it can't be used without
password.

So, if you don't want to provide CURLOPT_USERPWD first, your program would
need to check for the HTTP return code, and if you get a 401 back, you just
re-send the same request with the username and password filled in
appropriately.

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
-------------------------------------------------------
Sponsored by:
ThinkGeek at http://www.ThinkGeek.com/
Received on 2002-06-21