【发布时间】:2019-06-17 13:52:32
【问题描述】:
我正在研究 Rest-Assured 框架。
我正在使用http://ziptasticapi.com 免费 API 进行练习。
当我打电话时:
final static String BASE_URI = "http://ziptasticapi.com/";
final static String ADAK_ZIP_CODE = "99546"; //{"country":"US","state":"AK","city":"ADAK"}
final static String ATKA_ZIP_CODE = "99547";
public static final String GET_METHOD = "GET";
RestAssured.baseURI = BASE_URI;
String responseString = when().get(ADAK_ZIP_CODE).then()
.statusCode(200)
.and()
.extract()
.asString();
System.out.println(responseString);
我得到以下字符串:
{"country":"US","state":"AK","city":"ADAK"}
作为 responseString 值。
当我尝试时:
RestAssured.baseURI = BASE_URI;
ZipData zipdata = when().get(ADAK_ZIP_CODE).then()
.statusCode(200)
.and()
.extract()
.as(ZipData.class);
public class ZipData {
public String country;
public String state;
public String city;
}
我崩溃了:
java.lang.IllegalStateException:无法解析对象,因为没有 在响应中指定了受支持的 Content-Type。内容类型原为 'text/html;charset=UTF-8'。
这是为什么呢?可能是其余的返回 Html 而不是 Json?我该如何处理?
谢谢!
【问题讨论】:
标签: rest rest-assured rest-assured-jsonpath