rest-assured - 如何使用放心的方式做出正确的获取请求?
问题描述
我确实获取对 api 的请求
公共类 Req1 {
public static void main(String[] arg) {
RestAssured.config = RestAssured.config().encoderConfig(encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false));
Response response = given()
.header("Accept", "application/json")
.header("PWT", "123123123123")
.header("Referer", "https://xxxxxxx.ru/")
.header("Sec-Fetch-Mode", "cors")
.header("X-Auth-Token", "123123123123")
.header("X-User-Lang","rus")
.body("dateEnd=2019-09-17&dateStart=2019-09-17&limit=100&officeCode=270&offset=0&onlyEmpty=false&typeBasis=\n")
.baseUri("https://xxxxx.ru")
.get();
System.out.println(response.body().asString());
}
}
但请求不使用正文 -> 我得到的结果没有 dateEnd、officeCode 等
解决方案
你可以这样使用。这将打印请求。如您所见, Body 确实包含您要发送的内容。
我认为,代码在您编写时正在工作。请检查身体是否正确。
Response response = given().header("Accept", "application/json").header("PWT", "123123123123")
.header("Referer", "https://xxxxxxx.ru/").header("Sec-Fetch-Mode", "cors")
.header("X-Auth-Token", "123123123123").header("X-User-Lang", "rus")
.body("dateEnd=2019-09-17&dateStart=2019-09-17&limit=100&officeCode=270&offset=0&onlyEmpty=false&typeBasis=\n")
.baseUri("https://xxxxx.ru").log().all().get();
System.out.println(response.body().asString());
推荐阅读
- openstreetmap - 检查关系是否完全在区域内
- ansible - Ansible 在联合操作期间更改了事实值
- kotlin - 如何收听 Firestore 文档中的地图值?
- varnish - Varnish 6.6.1 意外恐慌:在 sml_trimstore()、storage/storage_simple.c 中断言错误
- sharepoint - 有没有办法从 Sharepoint 中的模板作为按钮创建新文档?
- python - slundberg / shap中GPUTree和TreeExplainer之间的差异
- r - 从默认更改 geom_ribbon() 的路径顺序
- node.js - 为什么我会收到此错误 --> 当我在线托管我的应用程序时,操作 `users.findOne()` 缓冲在 10000 毫秒后超时
- python - 如何在 Entrez.esearch 中使用 txt 文件内容作为搜索词?
- html - 单选输入上的垂直对齐文本