如何在Restful Web服务中发送XML文件端点URL [英] How to sent XML file endpoint url in Restful web service

查看:149
本文介绍了如何在Restful Web服务中发送XML文件端点URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将请求XML文件作为多部分表单数据发送到{url}. Restful 网络服务中的操作方式.在我在那里使用之前,

I need to send the request XML file to {url} as multipart form data. How this do in Restful web service. Before I use in there in,

RequestDispatcher rd = request.getRequestDispatcher("/file/message.jsp");
rd.forward(request, response);

但这不是在特定的{url}中发送的,如何发送?

But this isn't sent in specific {url}, How to sent it?

推荐答案

您可以使用Jersey Rest Client将XML消息作为post request发送.

You can use the Jersey Rest Client to send your XML message as post request.

try {
    Client client = Client.create();

    WebResource webResource = client.resource(http://<your URI>);

    // POST method
    ClientResponse response = webResource.accept("multipart/form-data").type("multipart/form-data").post(ClientResponse.class, "<your XML message>");

    // check response status code
    if (response.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
    }

    // display response
    String output = response.getEntity(String.class);
    System.out.println("Output from Server .... ");
    System.out.println(output + "\n");
} catch (Exception e) {
     e.printStackTrace();
}

对于Jersey客户,您可以在此处找到文档:

For Jersey Client you can find documentation here:

Jersey REST Client

WebResource

这篇关于如何在Restful Web服务中发送XML文件端点URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆