请求正文正在控制台中打印出来,但没有打印出响应

问题描述

我正在尝试构建基于 Java、RestAssured 和 Cucumber 的 Rest API 自动化。我试图通过 POST 到达端点。问题是当我将响应转换为字符串并且打印响应时,它打印的是 XML 文件内容而不是响应。我还看到状态代码为 200。我不确定这里出了什么问题。以下是我的代码库中的示例片段。

我正在尝试访问 WebService (SOAP WSDL)。

// required imports

public class Service_Steps {

  Response xmlResponse;


    @When("I create a POST request for RCP for endpoint using XML")
    public void i_create_a_post_request_for_endpoint_using_xml() {
   
    // xml Request body
    String path = "pah_to_xml_file";

    File file = new File(path);

    xmlResponse = RestAssured.given().when().relaxedHTTPSValidation().accept(ContentType.XML).header(<headers>)
                    .body(file)
                    .post(url);
            
    String xmlResponseAsstring = xmlResponse.then().extract().body().asstring();
    
}

不知道为什么我会看到这种歧义。有时打印响应,有时打印 XML 文件(请求正文)内容

解决方法

在与开发人员核实后,我了解到 SOAP EndPoint 以两种不同的方式随机发送响应!

,

试试这个:

   xmlResponse = RestAssured.given().log().all().when().relaxedHTTPSValidation().accept(ContentType.XML).header(<headers>)
                    .body(file)
                    .post(url)
                    .then()
                    .log().all()
                    .extract()
                    .response();

这将打印出所有的请求和响应内容