1
我想通過POST提交一些JSON到RestAssured端點。 API正在期待一個關鍵的列表。我需要發送的值是包含單個項目的列表。發送一個項目列表作爲formParam與RestAssured
理想的請求將是這樣的:
Request method: POST
Request path: http://localhost:8080/registrionURL
Request params: <none>
Query params: <none>
Form params: paramKey=[param space]
Path params: <none>
Multiparts: <none>
如果我添加帕拉姆列表或地圖它仍然只是將參數作爲字符串:
String paramKey = "paramKey";
String paramWithSpace = "param space";
Response response = RestAssured.given()
.formParam(paramKey, new String[]{paramWithSpace})
.and().contentType("application/json")
.log().method().log().path().log().parameters()
.when().post(MessageFormat.format(registrationUrl, testName));
輸出:
Request method: POST
Request path: http://localhost:8080/registrionURL
Request params: <none>
Query params: <none>
Form params: paramKey=param space
Path params: <none>
Multiparts: <none>
看來正常的方法是多次撥打.formParam()
創建一個列表:
String paramKey = "paramKey";
String paramWithSpace = "param space";
Response response = RestAssured.given()
.formParam(paramKey, paramWithSpace)
.formParam(paramKey, paramWithSpace)
.and().contentType("application/json")
.log().method().log().path().log().parameters()
.when().post(MessageFormat.format(registrationUrl, testName));
輸出:
Request method: POST
Request path: http://localhost:8080/registrionURL
Request params: <none>
Query params: <none>
Form params: paramKey=[param space, param space]
Path params: <none>
Multiparts: <none>
有誰知道如何發送長度爲1的列表作爲形式參數?
捂臉,我試着做一個參數映射列表中這似乎並沒有工作,然後從未嘗試過的列表中'.formParam ()'。非常好,謝謝! – immulatin