【问题标题】:How to set the content type in interceptors in rest assured?如何在放心的拦截器中设置内容类型?
【发布时间】:2021-04-05 07:09:58
【问题描述】:

我已经在拦截器中设置了内容类型,但是在运行 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");
    }
}

如果我缺少任何步骤,请帮助我。

【问题讨论】:

标签: java rest-assured


【解决方案1】:

试试 contentType(ContentType.JSON)

【讨论】:

    【解决方案2】:

    下面的例子是在发送请求之前设置 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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 2019-05-23
      • 1970-01-01
      相关资源
      最近更新 更多