放心地得到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());
}
您使用错误的标题进行接受。 content-type
告诉服务器您发送的请求正文;你想使用accept
告诉服务器你想要什么类型的响应。
需要添加两者
.header("Content-Type","application/json" )
.header("Accept","application/json" )