使用RESTAssured从HTML中获取XML结果。

问题描述 投票:0回答:1

我正在面临一些情况,我以为事情会很琐碎,一样平常不是那么回事。

我正在对一个网站进行GET调用,返回的结果是HTML,有很多的

RequestSpecification requestSpecification = initRequest()
            .basePath("myPathHere");

    Response response = requestSpecification.get().then().contentType(ContentType.HTML)
            .extract().response();

到目前为止,一切都很好,但后来当我试图转换为XML,它给我空的结果。

我试过

XmlPath htmlPath = new XmlPath(CompatibilityMode.XML, response.getBody().asString());

XmlPath htmlPath = new XmlPath(CompatibilityMode.HTML, response.getBody().asString());

我查了一下google上的东西很乱,那应该是很简单的,但为什么它不是?

java rest-assured
1个回答
0
投票

试试这个。

RequestSpecification requestSpecification = initRequest()
                                              .basePath("myPathHere");

XmlPath htmlPath = requestSpecification
                      .get()
                      .xmlPath();

或者这个

RequestSpecification requestSpecification = initRequest()
                                              .basePath("myPathHere");

XmlPath htmlPath = requestSpecification
                      .get()
                      .then()
                      .extract()
                         .path('');
© www.soinside.com 2019 - 2024. All rights reserved.