gpt4 book ai didi

java.lang.IllegalStateException : You can either send form parameters OR body content in POST, 不是两者

转载 作者:行者123 更新时间:2023-12-03 08:44:55 24 4
gpt4 key购买 nike

我对发布请求感到很陌生,但我遇到了以下错误

java.lang.IllegalStateException: You can either send form parameters OR body content in POST, not both!

这是我的测试

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());

}

我正在使用 RestAssured 3.0.2 依赖项它确实工作正常,突然出现错误,任何帮助将不胜感激

最佳答案

POST 的

.Param 将默认为表单参数,因此您需要将其明确指定为 .queryParam

given().
queryParam("name, "asdasdh).
body(..).
when().

关于java.lang.IllegalStateException : You can either send form parameters OR body content in POST, 不是两者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61863830/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com