我正在以以下方式形成io.assertassured请求/响应
Response response = RestAssured.given().headers("Authorization", "Bearer token).contentType(ContentType.JSON).body(tempJsonString).post(MY_ENDPOINT).
andReturn();
我想逐步创建请求,例如,
//Authorization
RequestObject request = RestAssured.given().headers("Authorization", "Bearer"+token);
//Adding body; tempJsonString is already defined
request = request.body(tempJsonString);
//Adding HTTP Verb; MY_ENDPOINT is already defined
request = request.post(MY_ENDPOINT)
//Finally
Response response = request().andReturn();
io.restassured DSL是否可能?
答案 0 :(得分:0)
您可以使用 io.restassured.builder.RequestSpecBuilder 类
RequestSpecBuilder requestBuilder = new RequestSpecBuilder();
requestBuilder.setBaseUri("http://www.example.com");
requestBuilder.setBasePath("/path");
requestBuilder.addHeader("Authorization", "Bearer" + token);
RequestSpecification request = RestAssured.given().spec(requestBuilder.build()).when();
Response response = request.post().andReturn();