java – Jersey REST Client:发布MultiPart数据
发布时间:2020-12-15 05:12:38 所属栏目:Java 来源:网络整理
导读:我正在尝试编写一个Jersey客户端应用程序,它可以将多部分表单数据发布到Restful Jersey服务.我需要发布带有数据的CSV文件和带有元数据的 JSON.我正在使用Jersey客户端1.18.3.这是我的代码(一些名称已被更改为公司保密)… Client client = Client.create();We
我正在尝试编写一个Jersey客户端应用程序,它可以将多部分表单数据发布到Restful Jersey服务.我需要发布带有数据的CSV文件和带有元数据的
JSON.我正在使用Jersey客户端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) 解决方法
查看 您需要使用重载的 所以你应该做的事情 ClientResponse response = webResource .type(MediaType.MULTIPART_FORM_DATA_TYPE) .post(ClientResponse.class,multipartEntity); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |