如何使用 Rest Assured 将多个文件作为输入传递给 api [英] How to pass multiple files as a input to an api using Rest Assured

查看:45
本文介绍了如何使用 Rest Assured 将多个文件作为输入传递给 api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的这个方法中,我对本地运行的 API 进行了 API 调用,该 API 只接受一个文件作为请求,但是有没有任何可能的方法来进行 API 调用,在运行时使用 Rest Assured 动态地接受多个文件作为请求基于对该 API 的请求的时间?像如何在运行时动态地在 Rest Assured 中添加多个文件作为 API 请求?

In this method below I was making an API call to a locally running API that accepts only one file as a request, but is there any possible way to make an API call that accepts multiple files as request using Rest Assured dynamically at run time based on requests for that API? like how to add multiple files as an API request in Rest Assured at run time dynamically?

    public String restTest() {
        String resp = RestAssured.given().multiPart("file", new File("C:/Local/file/path/LocalFiles/file.txt")).when().post("http://localhost:4444/local/upload").then().assertThat().statusCode(200).and().extract().body().asString();

    return resp.toString();
        
    }

推荐答案

public static void main(String[] args) throws MalformedURLException {

        Response response;
        RequestSpecification request = RestAssured.given().header("content-type", "multipart/form-data");
        for (int i = 1; i <= 2; i++) {
            request.multiPart("file", new File("D:/testtemplates98_" + i + "Data.xlsx"));// File parameters will be
                                                                                            // dynamic
        }
        response = request.post(new URL("https://jquery-file-upload.appspot.com/"));
        System.out.println(response.getBody().asString());
}

这篇关于如何使用 Rest Assured 将多个文件作为输入传递给 api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆