我正在尝试使用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上传的方法。
到目前为止,我已尝试过(修改路径和网址以保护内疚):
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个回复。
不幸的是,由于我无法控制的情况,切换到其他版本不是一种选择。任何帮助将不胜感激!