【发布时间】:2018-03-01 13:19:55
【问题描述】:
放心得到 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());
}
【问题讨论】:
-
我在请求中添加了这个,现在它工作正常。 contentType("应用程序/json")
标签: java rest rest-assured