用于Mulipart调用的java Jersey客户端
我正在使用jersey
客户端对API进行REST调用,该API在mulipart中返回Json和PDF文件作为响应的第一部分和第二部分
final Client client = ClientBuilder.newClient();
final WebTarget target = client.target(endPoint);
final Builder request = target.request().header("Authorization", authKey);
final Response response = request.get();
final String readEntity = response.readEntity(String.class);
这将以字节码格式返回PDF文件的字符串响应。 我试图将实体读取为多部分类,然后出现异常:
Message Body Reader Not found for media type=multipart/form-data;boundary=------#### and the getMediaType() call on client returns multipart/form-data;boundary=------####.
使用上述客户端解析此多部分响应的正确方法是什么
# 1 楼答案
快速的谷歌搜索会给你结果。您必须启用
MultiPartFeature
并且必须启用response.readEntity(InputStream.class)
从http://www.benchresources.net/jersey-2-x-web-service-for-uploadingdownloading-zip-file-java-client/获取以下代码
# 2 楼答案
我希望下面的代码将帮助您