RestAssured:发送请求后如何获取 RequestSpecification 字段或参数?

RestAssured: How can I get the RequestSpecification fields or parameters after sending a request?

我正在做黄瓜 bdd 测试我有一个 class [MyClient] 包装了放心的方法,我有多个 class 调用 [MyClient].

我可以使用 put、post 等方法,但我想知道是否有办法让我获得实际的 request 字段(header, body...) 完成请求后发送。

我在获取和解析响应方面也没有任何问题,但我无法发送请求。

考虑到以下情况,我可以调用 sendPostRequest()RequestSpecification 实例存储到名为 request 的字段中,我可以随时通过调用 getter.但是,我无法从 RequestSpecification object 中获取各个字段。从 debugger,我可以看到这些字段很好,所以我想必须有一些干净的方法来获取它。

我已经尝试过 log(),但它似乎无法满足我的需求。 感谢您的帮助!!

呼叫中 CLASS:

public class MyInterfaceSteps() {
 private myClient = new MyClient();

 public sendPostRequest(){
  myClient.post(someHeaders, someBody, someUrl);
 }
}

客户CLASS:

public class MyClient() {
 private RequestSpecification request;
 private Response response;

 public getRequest() {
  return request;
 }

 public getResponse() {
  return response;
 }

 public Response post(Map<String, String> headers, String body, String url) {
  request = given().headers(headers).contentType(ContentType.JSON).body(body);
  response = request.post(url);  
 }
}

您创建了一个过滤器 (https://github.com/rest-assured/rest-assured/wiki/Usage#filters) which gives you access to FilterableRequestSpecification (http://static.javadoc.io/io.rest-assured/rest-assured/3.0.3/io/restassured/specification/FilterableRequestSpecification.html),您可以从中获取(和修改)例如headers 和 body 等。过滤器可以将这些值存储到您选择的数据结构中。