我面临着一些情况,我认为事情会非常琐碎,像往常一样不是那么多。
我正在获取对站点的 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());
我查了一下谷歌,事情很困惑,这应该很容易,但为什么不呢?
最佳答案
试试这个:
RequestSpecification requestSpecification = initRequest()
.basePath("myPathHere");
XmlPath htmlPath = requestSpecification
.get()
.xmlPath();
或者这个:
RequestSpecification requestSpecification = initRequest()
.basePath("myPathHere");
XmlPath htmlPath = requestSpecification
.get()
.then()
.extract()
.path('');
关于java - 使用 RESTAssured 从 HTML 获取 XML 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62388449/