【问题标题】:Testing API with Curl使用 Curl 测试 API
【发布时间】:2015-04-01 14:25:37
【问题描述】:

我正在用 Flask 编写 API。使用浏览器进行测试效果很好:

http://stuff.com/login?username=test@test.com&password=testpassword

返回我所期望的。

但是,我尝试以两种方式将其输入 curl(请原谅我的无知,LAMP 新手)

卷曲http://stuff.com/login?username=test@test.com&password=testpassword

curl -i http://stuff.com/login?username=test@test.com&password=testpassword

不幸的是,查询中的变量没有发送到服务器,因为我的错误消息类似于传递:

http://stuff.com/login?username=

帮助?

【问题讨论】:

  • 我不确定,但这有帮助吗:superuser.com/questions/149329/… ?
  • 尝试用单引号括住网址:curl 'http://stuff.com/login?username=test@test.com&password=testpassword'
  • 明白了。谢谢。随意回答,我会验证的。

标签: api http curl lamp


【解决方案1】:

我相信原因是您的 shell 正在评估您正在使用的 GET 参数,而不是将它们作为字符串传递。为防止这种情况,请在请求 url 周围使用单引号。例如:

curl 'http://stuff.com/login?username=test@test.com&password=testpassword'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-21
    • 2016-09-23
    • 2014-01-10
    • 2011-09-09
    相关资源
    最近更新 更多