使用Jersey开发RESTful服务时,如果用到上传附件功能,需要下载依赖包:mimepull.jar
如果使用jersey-1.17,那么需要的是mimepull-1.3.jar
客户端的测试案例:
public void test() throws Exception { File xml = new File("T:\\xiamenair_trunk\\PublishPackage.zip"); FormDataMultiPart fdmp = new FormDataMultiPart(); fdmp.bodyPart(new FileDataBodyPart("package",xml,MediaType.APPLICATION_OCTET_STREAM_TYPE)); Client c = ClientFactory.getClient(); WebResource wr = c.resource("http://localhost:8080/publishserver/restful/").path("/PublishEngineerFiles"); String reString = wr.type(MediaType.MULTIPART_FORM_DATA).post(String.class,fdmp); System.out.println(reString); }