如何使用jodd-http上传多个文件?

时间:2019-05-22 01:30:57

标签: jodd

如何使用jodd HTTP在同一请求中上传多文件?

我尝试了以下操作,但仅发布了第一个文件。

HttpRequest httpRequest = HttpRequest
        .post("http://srv:8080/api/dlapp/add-file-entry")
        .form(
            "title", "test",
            "description", "Upload test",
            "file", new File("d:\\a.jpg.zip"),
            "file", new File("d:\\b.jpg.zip")
        );

    HttpResponse httpResponse = httpRequest.send();

1 个答案:

答案 0 :(得分:1)

那是正确的代码。您只需添加文件参数:

HttpRequest httpRequest = HttpRequest.post("localhost:8173/echo")
        .form(
            "title", "test",
            "description", "Upload test",
            "file1", temp1,
            "file2", temp2
        );

仅此而已。有the testcase会对此进行检查。

最简单的检查方法是启动例如Wireshark在您的本地计算机上,只需检查请求即可;其中必须有两个文件块。

由于某种原因,您的服务器端是否可能不接受文件?

您是否使用最新版本(v5.0.x)?

p.s。如果要发送两个文件,请使用两个不同的参数名称(例如file1file2)。

相关问题