开发者

How to post an XML file using a REST Client in Jersey

I want to send an XML file and receive the response back as an XML file. The code that I am trying throws an exception, please could someone help. I am not sure what is going wrong here

ClientConfig config =开发者_JAVA百科 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);


try it

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜