gpt4 book ai didi

java - 通过 Rest Assured 获取 Rest API URI 的状态代码 415 但通过 Rest Client 工作正常

转载 作者:行者123 更新时间:2023-11-30 10:18:48 24 4
gpt4 key购买 nike

安心拿到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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com