内容简介:翻译自:https://stackoverflow.com/questions/15585074/jersey-client-exception-a-message-body-writer-was-not-found
我正在使用Jersey客户端来访问 PHP
Web服务以获取图像上载功能.我收到以下异常:
Caused by: com.sun.jersey.api.client.ClientHandlerException:
A message body writer for Java type, class
com.sun.jersey.multipart.FormDataMultiPart, and MIME media type,
multipart/form-data, was not found
at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:288)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:204)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
... 63 more
这是我正在使用的代码:
WebResource webResource = Client.create().resource(HTTP_REST_URI);
JSONObject jSONObj = webResource.queryParams(queryParams)
.type(MediaType.MULTIPART_FORM_DATA)
.post(JSONObject.class, formDataMultiPart);
如何解决这个异常?
创建客户端时注册MultiPartWriter提供程序:
ClientConfig cc = new DefaultClientConfig(); Client client; cc.getClasses().add(MultiPartWriter.class); client = Client.create(cc);
如果使用Maven,这些是你在pom.xml中需要的依赖项:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.17.1</version>
</dependency>
翻译自:https://stackoverflow.com/questions/15585074/jersey-client-exception-a-message-body-writer-was-not-found
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- python编程(wx客户端编写)
- Swift编写--仿照Twitter客户端
- Golang编写客户端、服务端并实现文件传输
- 使用Python编写批量添加图片水印程序:二、桌面客户端
- Kafka-php:使用 PHP 编写的 Kafka 客户端
- 支付宝客户端架构解析:iOS 客户端启动性能优化初探
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Trading and Exchanges
Larry Harris / Oxford University Press, USA / 2002-10-24 / USD 95.00
This book is about trading, the people who trade securities and contracts, the marketplaces where they trade, and the rules that govern it. Readers will learn about investors, brokers, dealers, arbit......一起来看看 《Trading and Exchanges》 这本书的介绍吧!