JSON API 无法正确读取 REST Assured 请求



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

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 响应。我通过邮递员发送相同的请求,它工作得很好。唯一的区别是"断言"部分。邮递员请求后,它看起来像:

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: %{}
}
},

在放心请求之后,它是空的:

assigns: %{},

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

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

相关内容

  • 没有找到相关文章

最新更新