[英]API returning text/html rather than JSON when triggered using RestArrured
I'm triggering the Zomato api for the collections request, however, I keep getting the headers as if they were text/html.我正在为集合请求触发 Zomato api,但是,我一直在获取标题,就好像它们是 text/html 一样。 Postman returns them as JSON, which is what I need.邮递员将它们作为 JSON 返回,这正是我所需要的。 All other Zomato apis I've tested so far are returning JSON but collections and not sure why.所有其他Zomato的API到目前为止,我测试了正在返回JSON,但收藏品和不知道为什么。 That's what I have on my attempts to force the JSON as the type for the response.这就是我试图将 JSON 强制为响应类型的尝试。
@Test
public void testGetCousinesApiReturnsItemsInAscendingAlphabeticalOrder() {
Map<String, Object> map = new HashMap<>();
map.put("city_id", 61);
Response r = given()
.baseUri(baseUrl)
.basePath("/cousines")
.queryParams(map)
.contentType(ContentType.JSON)
.accept(ContentType.JSON)
.contentType("application/json\r\n")
.header("Accept", "application/json").and()
.header("Content-Type", "application/json")
.header("user-key", zomatoKey)
.log().body(false)
.get();
System.out.println(r.getContentType());
}
I convert response to JsonPath :我将响应转换为 JsonPath :
public static JsonPath getJsonPath (Response res) {
String json = res.asString();
System.out.println("returned json: " + json);
return new JsonPath(json);
}
and then use this JsonPath to get each value of Response:然后使用这个 JsonPath 来获取 Response 的每个值:
JsonPath jp = getJsonPath(res);
String type = jp.get("type");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.