How to get the xml response from RestAssured Response

时间:2017-05-16 09:36:45

标签: rest-assured

My Rest API Response is XML, how to handle the response.

My RestAPI code will be as follows:

Response res = given()
        .relaxedHTTPSValidation()
        .body("configtype=temperaturesysconfig")
        .with()
        .contentType(ConfigReader.get("application.json"))
        .then()
        .post(ConfigReader.get("config.base.url") + ConfigReader.get("query.temperaturesysconfig.url"));

Response will be in res variable, i can get the response from as

res.body().toString() but it is not coming as xml, the result is as com.jayway.restassured.internal.RestAssuredResponseImpl@4390f46e.

How to get it as xml?

1 个答案:

答案 0 :(得分:0)

在进行REST调用之前,请尝试为响应显式注册XML解析器,如下所示。

registerParser("application/xml", Parser.XML);

Response res = 
      given()
        .relaxedHTTPSValidation()
        .body("configtype=temperaturesysconfig")
        .with()
        .contentType(ConfigReader.get("application.json"))
      .then()
        .post(ConfigReader.get("config.base.url") +
              ConfigReader.get("query.temperaturesysconfig.url"));

System.out.println(res.body().toString());