我正在尝试构建一个基于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端点以两种不同的方式随机发送响应!
试试这个:
xmlResponse = RestAssured.given().log().all().when().relaxedHTTPSValidation().accept(ContentType.XML).header(<headers>)
.body(file)
.post(url)
.then()
.log().all()
.extract()
.response();
这将打印出所有的请求&响应物质