我想访问一个需要用户名/密码的URL。我想用curl访问它。现在我正在做的事情是:

curl http://api.somesite.com/test/blah?something=123

我得到一个错误。我想我需要在上面的命令中指定用户名和密码。

我该怎么做呢?


当前回答

要让密码至少不弹出在你的.bash_history:

curl -u user:$(cat .password-file) http://example-domain.tld

其他回答

通常CURL命令指的是

curl https://example.com\?param\=ParamValue -u USERNAME:PASSWORD

如果您没有任何密码或想跳过命令提示符来要求输入密码,请将密码部分留空。

即curl https://example.com\?param\=ParamValue -u USERNAME:

使用-u标志来包含用户名,curl将提示输入密码:

curl -u username http://example.com

你也可以在命令中包含密码,但你的密码将在bash历史中可见:

curl -u username:password http://example.com

很简单,做以下几点:

curl -X GET/POST/PUT <URL> -u username:password

你可以使用命令,

curl -u user-name -p http://www.example.com/path-to-file/file-name.ext > new-file-name.ext

HTTP密码将被触发。

参考: http://www.asempt.com/article/how-use-curl-http-password-protected-site

或者同样的东西,但是语法不同

curl http://username:password@api.somesite.com/test/blah?something=123