Api 如何在Rest-Assured框架中使用POST方法
如何在rest-assured框架中使用post方法。 我正在使用Rest-Assured框架学习API,有人能帮我构造吗 我的代码:Api 如何在Rest-Assured框架中使用POST方法,api,testing,qa,rest-assured,Api,Testing,Qa,Rest Assured,如何在rest-assured框架中使用post方法。 我正在使用Rest-Assured框架学习API,有人能帮我构造吗 我的代码: RestAssured.baseURI ="https://reqres.in"; RequestSpecification request = RestAssured.given(); JSONObject requestParams = new JSONObject(); requestParams.put(
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
响应正文为:{“错误”:“缺少电子邮件或用户名”}
这是参考URL:
post方法是:注册成功
请帮帮我
谢谢您没有在下面的代码中添加标题第三行
RestAssured.baseURI = "https://reqres.in";
RequestSpecification request = RestAssured.given();
request.header("Content-Type","application/json");
JSONObject requestParams = new JSONObject();
谢谢你的帮助。