gpt4 book ai didi

api - 如何在 Rest Assured Framework 中使用 POST 方法

转载 作者:行者123 更新时间:2023-11-28 20:26:49 25 4
gpt4 key购买 nike

如何在放心框架中使用 post 方法。
我正在通过使用 Rest Assured Framework 来学习 API,任何人都可以帮助我如何构建

我的代码:

    RestAssured.baseURI ="https://reqres.in";
RequestSpecification request = RestAssured.given();

JSONObject requestParams = new JSONObject();
requestParams.put("email", "sydney@fife");
requestParams.put("password", "pistol444");
request.body(requestParams.toJSONString());
Response response = request.post("/api/register");

int statusCode = response.getStatusCode();
System.out.println("API response code is :" + statusCode);
String body =response.asString();
System.out.println("Response body is : "+ body);

使用此 Post 方法后收到错误消息:

API 响应代码为:400
响应正文是:{"error":"Missing email or username"}

这是引用网址: https://reqres.in/
和发布方法是:注册 - 成功

请帮我 。

谢谢

最佳答案

您还没有添加标题,下面代码中的第三行

RestAssured.baseURI = "https://reqres.in";

RequestSpecification request = RestAssured.given();
request.header("Content-Type","application/json");

JSONObject requestParams = new JSONObject();

关于api - 如何在 Rest Assured Framework 中使用 POST 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53044017/

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