java - 如何在放心的拦截器中设置内容类型?
问题描述
我已经在拦截器中设置了内容类型,但是在运行 API 时,没有调用拦截器。
package com.gdn.qa.module.athens.api.interceptors;
import com.gdn.qa.automation.core.restassured.ServiceInterceptor;
import io.restassured.specification.RequestSpecification;
import static io.restassured.RestAssured.given;
public class AthensIAGInterceptor implements ServiceInterceptor {
@Override
public boolean isSupport(String serviceName) {
if (serviceName.equalsIgnoreCase("athens_iag")) {
return true;
}
return false;
}
enter code here
@Override
public void prepare(RequestSpecification resp1) {
resp1 = given().log().all().contentType("application/json");
}
}
如果我缺少任何步骤,请帮助我。
解决方案
下面的示例是在发送请求之前设置 contentType(ContentType.JSON),同样在响应中,您可以通过将其放在 then() 之后来验证它是否相同。
given().contentType(ContentType.JSON).queryParam("page","2").when().get("https://reqres.in/api/users").then().contentType(ContentType.JSON).assertThat().statusCode(200).log().all();
推荐阅读
- c# - API 中的 post 方法未按预期工作
- swift - 问:如何添加多个对象 AR 检测
- python - 抓取 Twitter 数据时出现 JSONDecodeError
- google-maps - [浏览器][cordova.js][xhrStatusChangeHandler] 无法 XHR config.xml:未找到
- jquery - 如何允许 filterizr JQuery 插件进行分页
- android-studio - 如何在 Android Studio 中正确查找 NDK shaderc lib 并将其链接到您的项目中?
- javascript - Phaser 3: "Too many active WebGL contexts. Oldest context will be lost." warning and memory leak
- c# - 没有在课堂上获得价值
- javascript - 如何防止生成空的Birt报告
- ios - iOS Swift UIImage animation got struck while doing db and webservice stuff