使用curl附加多个查询字符串变量

dar*_*ren 25 django curl tastypie

当我尝试在ModelResource中使用authentication = ApiKeyAuthentication()时,我一直收到401响应.我看了Django Tastypie:如何使用API​​ Key进行身份验证,他使用get参数来解决他的问题.如果我尝试使用get参数,它会选择用户名而不是api_key!

这适用于浏览器

http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50
Run Code Online (Sandbox Code Playgroud)

通过终端中的curl发送不会拾取api_key参数

curl --dump-header - http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50
Run Code Online (Sandbox Code Playgroud)

为什么在使用curl并附加2个查询字符串参数时?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50,它只会拾取第一个参数.这不是正确的方法吗?

roc*_*ier 76

&在命令行中键入意味着在后台运行前面的命令(感谢@Maccesch),因为在将&其作为新命令处理后的任何内容.

尝试用引号括起网址.

curl --dump-header - "http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50"

  • 你是对的,`&`意味着在后台运行前面的命令.之后的字符串被视为新命令. (3认同)