我想发送一个XML文件并将响应作为XML文件接收回来。我正在尝试的代码抛出异常,请有人帮忙。我不确定这里出了什么问题
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
String response = service.type(MediaType.APPLICATION_XML).accept(MediaType.TEXT_XML).post(String.class, new File("post.xml"));
System.out.println(response);
答案 0 :(得分:8)
试试吧
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
String response = service.type(MediaType.APPLICATION_XML)
.accept(MediaType.TEXT_XML)
.entity(new File("post.xml"))
.post(String.class);
System.out.println(response);