为了帮助大家避免混淆,我将把问题重新表述为两部分。
首先:“如何使用 BASIC auth 使用浏览器发出经过身份验证的 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 上,我根本没有收到授权提示,只是显示我未获得授权的页面。某些网站没有正确实施基本身份验证工作流程,还是有什么问题?我还需要做什么?”
curl 文档说该-u
选项支持多种身份验证方法,Basic 是默认设置。