繁体   English   中英

使用 httpie 测试 REST API 的问题

[英]Issues in testing REST API with httpie

我已经从 Rest browsable API 在 Django REST 中创建了一个用于 CURD 操作的 API,我可以查看/更新/删除记录。 但是当我尝试通过 httpie 执行更新时,它不起作用。

网址 - > http://localhost:8000/api/user/profile/1/

结果来自浏览器->

 {
    "user": 3,
    "subject": [
        1,
        3,
        4
    ],
    "phone": "897897897",
    "address": "xcgsajgchagclkk"
}

httpie 请求 -> http PUT http://localhost:8000/api/user/profile/1/ user=3 subject=[1,2] phone=333 address=my

错误 ->

{
    "subject": [
        "Expected a list of items but got type \"unicode\"."
    ]
}

正如我们所看到的,错误是请求中发送的数据格式,但我正在发送主题[1,2]的列表。 那么为什么它会给出错误。

编辑:我的请求标题

HTTP/1.0 400 BAD REQUEST
Allow: GET, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Type: application/json
Date: Fri, 30 Oct 2015 05:33:58 GMT
Server: WSGIServer/0.1 Python/2.7.6
Vary: Accept, Cookie
X-Frame-Options: SAMEORIGIN

正如@BogdanIulianBursuc 在他的评论中所建议的,Httpie 使用不同的语法提交列表。

所以正确的语法是subject:='[1,2]'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM