我如何通过授权头使用cURL?(可在/usr/bin/curl中执行)。


当前回答

FWIW,在Mac OS上,我发现我需要用引号包围目标url时,它包含查询参数,例如,

curl -H "Authorization: Token xxxxxxxxxxxxxx" "https://www.example.com/?param=myparam"

其他回答

FWIW,在Mac OS上,我发现我需要用引号包围目标url时,它包含查询参数,例如,

curl -H "Authorization: Token xxxxxxxxxxxxxx" "https://www.example.com/?param=myparam"

只是添加,所以你不需要点击:

curl --user name:password http://www.example.com

或者如果你试图为OAuth 2发送身份验证:

curl -H "Authorization: OAuth <ACCESS_TOKEN>" http://www.example.com

注意,当你使用: curl -H "授权:token_str" http://www.example.com

token_str和Authorization必须用空格隔开,否则服务器端将无法获得HTTP_AUTHORIZATION环境。

这个例子包括以下内容:

POST请求 页眉内容类型 头授权 数据标志,JSON数据 Base64编码令牌 Ref-1:卷曲授权头 Ref-2: curl POST请求

curl -X POST -H "Content-Type: application/json" -d '{"name”:”Johnny B. Goode”, "email”:”johnny.b.goode@mail.com"}' -H "Authorization: Bearer $(echo -n  Guitar Maestro | base64)" https://url-address.com 

从curl 7.61.0开始,您可以使用——oauth2-bearer <token>选项来设置正确的承载授权标头。