[英]How does Restlet client handle media type of request?
I've got several newbie questions about how Restlet client handles media type header: 我有几个关于Restlet客户端如何处理媒体类型标题的新手问题:
Thanks a lot! 非常感谢!
If you rely on the ClientResource class, you can add a MediaType parameter to your put call, such as 如果您依赖ClientResource类,则可以将MediaType参数添加到put调用中,例如
put(myPojo, MediaType.APPLICATION_JSON);
UPDATE Actually, the extra media type parameter defines the accepted result type expected from the remote resource, but doesn't apply to the sent entity. 更新实际上,额外的媒体类型参数定义了从远程资源获得的可接受的结果类型,但不适用于发送的实体。
The control on the media type of the entity/POJO sent is based on the ConverterService default settings, which depends on the extensions available on your classpath and their respective order. 对发送的实体/ POJO的媒体类型的控制基于ConverterService的默认设置,该默认设置取决于类路径上可用的扩展及其各自的顺序。
You can have full control by directly invoking the 您可以直接调用
ClientResource cr = new ClientResource("http://targetDomain/path");
cr.put(cr.toRepresentation(myPojo, new Variant(MediaType.APPLICATION_JSON));
You also need to add the org.restlet.ext.jackson extension on your classpath and its dependencies. 您还需要在类路径及其依赖项上添加org.restlet.ext.jackson扩展名。 The XStream extension is another option.
XStream扩展是另一种选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.