我正在尝试通过POST将一些JSON提交到带有RestAssured的端点。API需要一个键的列表。为此,我需要发送的值是带有单个项的列表。
理想的请求应该是:
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>如果我将param添加为列表或映射,它仍然将参数作为字符串发送:
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>有人知道如何将长度列表作为表单参数发送吗?
发布于 2017-01-20 19:37:26
如果将表单参数作为List传递,它就会工作。
.formParam(paramKey, Arrays.asList(paramWithSpace))https://stackoverflow.com/questions/41753083
复制相似问题