安心拿到415错误。相同的 URI 在浏览器中与 Rest 客户端一起工作正常。我从 Rest 客户端收到响应代码 200。
public static Response response;
public static String jsonAsString;
@BeforeClass
public static void setupURL()
{
// here we setup the default URL and API base path to use throughout the tests
RestAssured.baseURI = "######url##########";
//RestAssured.basePath = "/api/v1";
RestAssured.authentication = basic("password", "password");
Header acceptJson = new Header("content-type", "application/json");
//RestAssured.given().contentType(ContentType.JSON);
RestAssured.given().header(acceptJson);
}
@Test
public void getImageThroughImageid(){
RequestSpecification httpRequest = RestAssured.given();
Response response = httpRequest.request(Method.GET, "/images/imageid");
System.out.println(response.getStatusCode());
}
最佳答案
需要同时添加
.header("Content-Type","application/json" )
.header("Accept","application/json" )
关于java - 通过 Rest Assured 获取 Rest API URI 的状态代码 415 但通过 Rest Client 工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49050592/