5

I used to use curl command in terminal to access a php web page to test some APIs in the web page. It works fine.

For example:

curl www.somesite.com -d parmetername=value 

Now this page has basic http authentication. I knew I just need to add -u to give the username and password. I also googled and almost everyone suggests to do the same as following:

curl -u username:password www.somesite.com -d parmetername=value
curl --user username:password www.somesite.com -d parmetername=value 

or

curl http://username:password@www.somesite.com -d parmetername=value

I have tried both of them, none of them works. I got the same error message as following:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Authorization Required</title>
</head><body>
<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
<p>Additionally, a 401 Authorization Required
error was encountered while trying to use an ErrorDocument to handle the request.</p>
<hr>
<address>Apache/2.2.29 (Unix) mod_ssl/2.2.29 OpenSSL/1.0.1e-fips mod_bwlimited/1.4 Server at www.somesite.com Port 80</address>
</body></html>

I have tried to access the website via browsers. After I typed in username and password in the prompt window. I can access to this website.

Does anyone know what's going on here? Thank you.

user3293338
  • 481
  • 1
  • 6
  • 16
  • Please re-check your attempt with username and password in URL, because that is working for me (on a personal server). – watery Sep 30 '15 at 17:04
  • Possible duplicate of http://stackoverflow.com/questions/3044315/how-to-set-the-authorization-header-using-curl – Jan Sep 30 '15 at 17:19
  • I tried several time and on different computers...not working... I am thinking if this has to do something with the server settings... – user3293338 Sep 30 '15 at 17:21
  • The solution mentioned in http://stackoverflow.com/questions/3044315/how-to-set-the-authorization- header-using-curl is same as my attempt 1. It is not working... – user3293338 Sep 30 '15 at 17:23

1 Answers1

1

When I had that problem, it turned out that the server would not accept the authentication scheme 'Basic', but curl uses 'Basic' unless told differently.

Check out curl's command line options regarding the authentication scheme. You can use --basic, --digest, --ntlm, --negotiate, and --anyauth. See curl's man pages for details.

While --anyauth or --negotiate sound like curl could negotiate the correct authentication method with the server, neither of them worked for me. Instead, I had to explicity use --digest, like so:

curl --digest -u username:password -d parm1=value1&parm2=value2&submit=true https://www.somesite.com 
not2savvy
  • 2,902
  • 3
  • 22
  • 37