【问题标题】:How to use POST method in Rest Assured Framework如何在 Rest Assured Framework 中使用 POST 方法
【发布时间】:2018-10-29 10:57:16
【问题描述】:

如何在放心框架中使用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/ 并且发布方法是:注册 - 成功

请帮帮我。

谢谢

【问题讨论】:

    标签: api testing qa rest-assured


    【解决方案1】:

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

    RestAssured.baseURI = "https://reqres.in";
    
    RequestSpecification request = RestAssured.given();
    request.header("Content-Type","application/json");
    
    JSONObject requestParams = new JSONObject();
    

    【讨论】:

    • 感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    • 2016-05-06
    • 2019-06-13
    • 2021-06-19
    • 1970-01-01
    相关资源
    最近更新 更多