如何使用 Jersey 客户端发布 XML 文件?
final WebResource service = client.resource(UriBuilder.fromUri(WSURI).build());
service.type(MediaType.APPLICATION_XML);
service.accept(MediaType.TEXT_PLAIN);
final Builder builder = service.header(HttpHeaders.AUTHORIZATION, HEADER);
File file = new File("/test.xml");
builder.entity(file);
final ClientResponse response = builder.post(ClientResponse.class);
我想发送一个 XML 文件并接收返回的响应。我正在尝试的代码给出了 400 BAD 请求,请有人帮忙。我不确定这里出了什么问题。
final WebResource service = client.resource(UriBuilder.fromUri(WSURI).build());
service.type(MediaType.APPLICATION_XML);
service.accept(MediaType.TEXT_PLAIN);
final Builder builder = service.header(HttpHeaders.AUTHORIZATION, HEADER);
File file = new File("/test.xml");
builder.entity(file);
final ClientResponse response = builder.post(ClientResponse.class);
I want to send an XML file and receive the response back. The code that I am trying gives 400 BAD request, please could someone help. I am not sure what is going wrong here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WebResource 是不可变的 - 它的方法返回一个新的构建器实例。因此,代码片段的第二行和第三行没有效果,因为您忽略了它们的结果。调用
entity()
方法时也是如此。您应该执行以下操作:WebResource is immutable - it's methods return a new builder instance. So, the 2nd and 3rd line of your code snippet have no effect, since you ignore their result. Same when you call the
entity()
method. You should do the following instead: