为了帮助大家避免混淆,我将分两部分重新阐述这个问题。
第一:“如何使用BASIC身份验证通过浏览器发出经过身份验证的HTTP请求?” 。
在浏览器中,您可以首先通过等待提示出现来进行http基本认证,或者如果遵循以下格式,则可以通过编辑URL来进行: http://myusername:mypassword@somesite.com
注意:如果您已经安装了命令行和curl,那么问题中提到的curl命令就可以了。;)
参考文献:
同样根据CURL手册页面https://curl.haxx.se/docs/manual.html
HTTP
Curl also supports user and password in HTTP URLs, thus you can pick a file
like:
curl http://name:passwd@machine.domain/full/path/to/file
or specify user and password separately like in
curl -u name:passwd http://machine.domain/full/path/to/file
HTTP offers many different methods of authentication and curl supports
several: Basic, Digest, NTLM and Negotiate (SPNEGO). Without telling which
method to use, curl defaults to Basic. You can also ask curl to pick the
most secure ones out of the ones that the server accepts for the given URL,
by using --anyauth.
NOTE! According to the URL specification, HTTP URLs can not contain a user
and password, so that style will not work when using curl via a proxy, even
though curl allows it at other times. When using a proxy, you _must_ use
the -u style for user and password.
第二个真正的问题是“但是,在somesite.com上,我根本没有得到任何授权提示,只是一个页面显示我未获得授权。某站点未正确实施Basic Auth工作流,或者是否存在某些问题?还有我需要做的吗?”
curl文档说该-u
选项支持多种身份验证方法,默认为Basic。