我对发布请求感到很陌生,但我遇到了以下错误
java.lang.IllegalStateException:您可以在 POST 中发送表单参数或正文内容,但不能同时发送两者!
这是我的测试
public void createModel() {
JSONObject obj2 = new JSONObject();
obj2.put("name", "hello1234");
List<JSONObject> list1 = new ArrayList<JSONObject>();
list1.add(obj2);
System.out.println(" i am list 1 " + list1);
JSONObject obj = new JSONObject();
obj.put("modes", list1);
System.out.println("i am a object \n" + obj.toString());
System.out.println("testtest " + obj);
Response response = httpRequest.auth().preemptive().basic("test", "test")
.given().contentType("application/json").body(obj.toString()).when().post("/modes").then().using()
.extract().response();
int statusCode = response.getStatusCode();
System.out.println(statusCode + " this is post");
System.out.println("This is body" + response.getBody().prettyPrint());
}
Run Code Online (Sandbox Code Playgroud)
我正在使用 RestAssured 3.0.2 依赖项它确实工作正常,突然出现错误,任何帮助将不胜感激
.Paramfor POST 将默认为表单参数,因此您需要明确提及它.queryParam
given().
queryParam("name, "asdasdh).
body(..).
when().
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3074 次 |
| 最近记录: |