Curl to prompt a User Name and Password

前端 未结 6 1949
臣服心动
臣服心动 2020-12-31 02:36

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 as

相关标签:
6条回答
  • 2020-12-31 02:42

    -H 'Authorization: Basic user:pass' user:pass must be encoded in base64

    0 讨论(0)
  • 2020-12-31 02:44

    you can use cookies there I think. The steps would be:

    1. If you try to curl "http://www.2nddomain.com/admin" with no cookies, it can return you a html login form.
    2. Your form's action would point to 2nd server and if the credentials were right, set the cookie there and return (redirect) to server 1.
    3. And if you curl again, you'd check the cookie on the other side and in this case, it could read that cookie and return you the admin page output instead.
    0 讨论(0)
  • 2020-12-31 02:48

    Thanks all of your responses!

    This is what I need, hope it helps someone!

    In Order to get the "password protected" URL/Folder via CURL, we need to supply the username/password into the CURL like an example @pizza said, But there are 2 more things.
    1-) We need a Prompt Here.
    2-) We Don't want to HardCoded the username and password on second domain.

    so, we will place PHP_AUTH_USER and password prompt at the top of the page, and then will pass the argument via CURL to the destination URL/Folder.

    Yes yes, I know it's simple, but sometime you just can't figure out on a correct dimensions..

    0 讨论(0)
  • 2020-12-31 02:50

    for .htaccess style password protection, You can code the userid password as in:

    curl -u userid:password http://.......

    0 讨论(0)
  • 2020-12-31 02:58

    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'.

    0 讨论(0)
  • 2020-12-31 03:02

    Try the following like :

    curl -su 'user' <url>
    

    It should prompt password for the user

    0 讨论(0)
提交回复
热议问题