【发布时间】:2015-02-26 23:23:57
【问题描述】:
我正在尝试编写一个 Jersey 客户端应用程序,它可以将多部分表单数据发布到 Restful Jersey 服务。我需要发布一个包含数据的 CSV 文件和一个包含元数据的 JSON。我正在使用泽西客户端 1.18.3。这是我的代码(某些名称已更改为公司机密)...
Client client = Client.create();
WebResource webResource = client.resource("http://localhost:8080/mariam/service/playWithDad");
FileDataBodyPart filePart = new FileDataBodyPart("file",
new File("C:/Users/Admin/Desktop/input/games.csv"));
String playWithDadMetaJson
= "{\n"
+ " \"sandboxIndicator\": true,\n"
+ " \"skipBadLines\": false,\n"
+ " \"fileSeparator\": \"COMMA\",\n"
+ " \"blockSize\": false,\n"
+ " \"gameUUID\": \"43a004c9-2130-4e75-8fd4-e5fccae31840\",\n"
+ " \"useFriends\": \"false\"\n"
+ "}\n"
+ "";
MultiPart multipartEntity = new FormDataMultiPart()
.field("meta", playWithDadMetaJson, MediaType.APPLICATION_JSON_TYPE)
.bodyPart(filePart);
ClientResponse response = webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(multipartEntity);
现在我在最后一行收到一个编译错误,说它无法从 void 转换为 ClientResponse。
我之前从这篇文章中得到了一些关于 RestFul 服务本身的指导。
Java Rest Jersey : Posting multiple types of data (File and JSON)
【问题讨论】:
标签: java rest jersey multipartform-data jersey-client