用卷曲附加多个查询字符串变量 [英] appending multiple querystring variables with curl

查看:123
本文介绍了用卷曲附加多个查询字符串变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



这在浏览器中有效

  http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50 

通过终端中的卷曲发送不能取得api_key参数

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

为什么使用curl并附加2个querystring参数,如?username = darren& api_key = 9999d318e43b8055ae32d011be5b045ad61dad50 只能拾取第一个。这是不是正确的方式?

解决方案

& 命令行意味着在后台运行前面的命令(感谢@Maccesch),因为& 被视为新命令之后的任何事情。



尝试用引号将网址打包。



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


I keep getting a 401 response when I try to use authentication = ApiKeyAuthentication() in my ModelResource. I looked at Django Tastypie: How to Authenticate with API Key and he uses the get parameters to solve his issue. If I try use get parameters it picks up username but not api_key!

This works in browser

http://127.0.0.1:8000/api/v1/spot/8/?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50

Sending via curl in terminal doesn't pickup api_key parameter

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

Why when using curl and appending 2 querystring parameters like ?username=darren&api_key=9999d318e43b8055ae32d011be5b045ad61dad50 does it only pickup the first one. Is this not the correct way?

解决方案

Typing & in the command line means run the preceding command in the background (thanks @Maccesch), because of this anything after the & is being treated as a new command.

Try wrapping the url in quotes.

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

这篇关于用卷曲附加多个查询字符串变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆