【问题标题】:How to send the nested JSON in body for POST method using Rest-assured如何使用 Rest-assured 在 POST 方法的正文中发送嵌套的 JSON
【发布时间】:2019-05-04 19:40:22
【问题描述】:

我有一个很长的 JSON 正文,它是一个数组。我需要在正文中发送此 POST 方法。我正在使用放心。怎么做?

【问题讨论】:

  • 请举例说明

标签: json rest-assured rest-assured-jsonpath


【解决方案1】:

如果它是一个静态文件,您可以将它放在您的代码库中,并使用以下代码使用 RestAssured 调用端点。


String url = "http://yourhost:port/endpoint"
File yourlargejsonfile = new File(System.getProperty("user.dir") + File.separator + "resources" + File.separator
                + "staticjsonfiles" + File.separator + "jsonfile.json");


Response response = RestAssured.given().body(yourlargejsonfile).and()
                .contentType(ContentType.JSON).when().post(endpoint).then().extract().response();

如果您想动态构建有效负载,我建议您创建 JSONObjects/Models Classes/Plain Old Java Objects。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-14
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 2020-10-02
    相关资源
    最近更新 更多