【发布时间】:2016-12-25 19:52:19
【问题描述】:
我正在尝试使用 jersey-client 1.18 将文件上传到远程 API,但我一直无法弄清楚如何。本质上,我想要做的相当于以下命令:
curl -sv "http://localhost:4567/api/image" -X POST -F "file=@test2.png" -F "description=a%20b%20dce"
但我无法辨别使用 jersey-client 1.x 将文件作为 multipart/form-data 上传的任何方式。
到目前为止,我已经尝试过(修改路径和 URL 以保护有罪者):
FileInputStream fileInputStream = new FileInputStream(new File("test2.png"));
Form form = new Form();
form.add("description", "a b dce");
form.add("file", IOUtils.toString(fileInputStream, "UTF-8"));
client.resource("http://localhost:4567/api/image")
.header("content-type", MediaType.MULTIPART_FORM_DATA)
.post(ClientResponse.class, form);
但我只收到了 400 条回复。
很遗憾,由于我无法控制的情况,无法切换到其他版本。任何帮助将不胜感激!
【问题讨论】:
标签: java jersey jersey-client jersey-1.0