Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl to prompt a User Name and Password

Tags:

I have a password protect web folder on my site, I am fetching that folder on another domain using Curl, what I want is: when I try to open the URL it should ask me the user name and password, instead of asking it display the "Authorization Required".

Example:

  • http://www.example.com/admin (password protected using htpasswrd htaccess)
  • http://www.2nddomain.com/admin

If I try to access the "a" url it ask me for the user name password. Fine. but it doesn't ask me for the user name and password on "b" (using curl here).

Any Idea?

In Short: I want to make Curl ask for the User/Password prompt.

Regards

I am not sure, if it is possible or not? but if it's possible so please let me know how, otherwise I will close this as "Invalid"

like image 644
mahaidery Avatar asked Mar 19 '12 22:03

mahaidery


People also ask

How do I use the curl command to request?

To make a GET request using Curl, run the curl command followed by the target URL. Curl automatically selects the HTTP GET request method unless you use the -X, --request, or -d command-line option. The target URL is passed as the first command-line option.

How do you send a header in curl?

To send an HTTP header with a Curl request, you can use the -H command-line option and pass the header name and value in "Key: Value" format. If you do not provide a value for the header, this will remove the standard header that Curl would otherwise send. The number of HTTP headers is unlimited.


2 Answers

Try the following like :

curl -su 'user' <url>

It should prompt password for the user

like image 180
Minh Nguyen Avatar answered Sep 30 '22 19:09

Minh Nguyen


Examples:

--user

curl -v --user myName:mySecret http://example.com/foo/bar

-u

curl -v -u myName:mySecret http://example.com/foo/bar

(example for Minh Nguyen see https://stackoverflow.com/a/26826658/3411766)

curl -v -su 'myName' http://example.com/foo/bar

asks for the pw of user 'myName'.

like image 44
cottton Avatar answered Sep 30 '22 20:09

cottton