【问题标题】:REST Assured request is not read properly by JSON apiJSON api 未正确读取 REST Assured 请求
【发布时间】:2019-02-18 13:07:20
【问题描述】:

我正在发送一些字符串,例如:

private final String test = "{\"data\":{\"type\":\"test\",\"attributes\":{\"color\":\"yellow\",\"name\":\"TestN\"}}}";

通过放心

given()
            .header("Origin", "http://localhost:5000")
            .header("Accept-Encoding", "gzip, deflate, br")
            .header("Accept-Language", "pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7")
            .header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36")
            .header("Content-Type", "application/vnd.api+json")
            .header("Accept", "application/vnd.api+json")
            .header("Cookie", "xxxxxx")
            .header("Connection", "keep-alive")
            .header("Cache-Control", "no-cache")
            .header("Host", "localhost:4400")
            .body(test).with()
            .log().everything()
            .when()
            .post(base + "test-endpoint")
            .then().statusCode(201);

不幸的是,API 以 500 响应。我正在通过 Postman 发送相同的请求,它运行良好。唯一的区别是“assings”部分。在邮递员请求之后,它看起来像:

assigns: %{
 doc: %Jabbax.Document{
   data: %Jabbax.Document.Resource{
     attributes: %{"appointment_color" => "yellow", "name" => "TestN"},
     id: nil,
     links: %{},
     meta: %{},
     relationships: %{},
     type: "test"
   },
   errors: [],
   included: [],
   jsonapi: %{version: "1.0"},
   links: %{},
   meta: %{}
 }
},

当在 Rest Assured 请求之后它是空的:

assigns: %{},

添加了所有标头,我尝试将其作为从 .json 文件解析的字符串发送。一切都给出相同的结果。有人知道可能是什么问题吗?

【问题讨论】:

    标签: java json postman rest-assured json-api


    【解决方案1】:

    线索是 REST Assured 添加了字符集信息 - 此处描述了类似的问题。

    【讨论】:

      猜你喜欢
      • 2017-11-25
      • 1970-01-01
      • 2017-03-20
      • 1970-01-01
      • 2017-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多