how to use curl command line to access a web page with HTTP Basic Authentication -
i used use curl command in terminal access php web page test apis in web page. works fine.
for example:
curl www.somesite.com -d parmetername=value now page has basic http authentication. knew need add -u give username , password. googled , suggests same 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. got same error message 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 not verify authorized access document requested. either supplied wrong credentials (e.g., bad password), or browser doesn't understand how supply credentials required.</p> <p>additionally, 401 authorization required error encountered while trying use errordocument handle request.</p> <hr> <address>apache/2.2.29 (unix) mod_ssl/2.2.29 openssl/1.0.1e-fips mod_bwlimited/1.4 server @ www.somesite.com port 80</address> </body></html> i have tried access website via browsers. after typed in username , password in prompt window. can access website.
does know what's going on here? thank you.
when had problem, turned out server not accept authentication scheme 'basic', curl uses 'basic' unless told differently.
check out curl's command line options regarding authentication scheme. can use --basic, --digest, --ntlm, --negotiate, , --anyauth. see curl's man pages details.
while --anyauth or --negotiate sound curl negotiate correct authentication method server, neither of them worked me. instead, had explicity use --digest, so:
curl --digest -u username:password -d parm1=value1&parm2=value2&submit=true https://www.somesite.com
Comments
Post a Comment