【问题标题】:How to use Curl to make a POST request with Dropwizard如何使用 Curl 通过 Dropwizard 发出 POST 请求
【发布时间】:2018-04-05 10:20:54
【问题描述】:

我有 Dropwizard 后端,喜欢使用 curl 使用 Json 主体发出 POST 请求

我使用 Postman 并选择了正文选项卡 raw 单选按钮和下拉菜单 JSON(applicattion/json) 上的设置。我输入了正文并能够成功创建 POST 请求。 但是,当我使用 curl 时出现错误。我用过

curl -v  -X POST "localhost:8080/resource" 
-H "Content-Type: application/json" 
-d '{label1: "words1", label2: "words2"}'

我收到错误消息

 {"code":400,"message":"Unable to process JSON"}

据我了解,由于 Postman 能够创建 POST 请求,因此 curl 存在问题。

【问题讨论】:

    标签: rest curl dropwizard


    【解决方案1】:

    这个

    {label1: "words1", label2: "words2"}
    

    不是 JSON。使用

    {"label1": "words1", "label2": "words2"}
    

    【讨论】:

    • 丹克,卢茨。这是我的错字
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-24
    • 2016-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-22
    • 2014-07-28
    相关资源
    最近更新 更多