How can I instruct curl to reuse credentials after it followed a redirect?

7

1

I know that curl can follow redirects (the -L argument), and I know that I can provide credentials to a request (-u username:password), but I want to use both all the way down the redirect chain.

How can I tell curl to reuse the username and password on every redirected location?

karatedog

Posted 2015-07-03T17:37:30.463

Reputation: 809

This would be useful to me..did you get a solution? – William Fleming – 2015-07-07T10:31:06.833

Btw i discovered wget can do this, but still have not figured out how to do it with curl.. – William Fleming – 2015-07-07T10:31:25.487

Answers

7

You can do this with the --location-trusted option:

allow sending the name + password to all hosts that the site may redirect to.

The libcurl option for this is CURLOPT_UNRESTRICTED_AUTH and it is available from curl version 7.10.4-pre6 (31 Mar 2003).

Sjoerd

Posted 2015-07-03T17:37:30.463

Reputation: 1 131

epic man curl overlook happened... – karatedog – 2015-12-02T13:32:03.033

0

According to this post, http://curl.haxx.se/mail/archive-2008-11/0067.html, the --anyauth argument could be a solution.

Toine42

Posted 2015-07-03T17:37:30.463

Reputation: 444

1I read this entry, but it is not the same problem. That HTTP request have multiple redirects,and one of those will ask for username and password,and asks if curl can use the provided credentials only when the webserver requests it. What I want is to instruct curl to use the credentials on every redirected URL. This might sound stupid, as there is no guarantee that every site uses the same credentials, but these sites are under my control and I set the same user/pass on them. (I am testing a desktop website, and wanted to check if it properly redirects if the UA is mobile) – karatedog – 2015-07-03T20:05:34.330