开发者

How to pass xml while requesting Rest web service

I want to pass xml to rest w开发者_运维知识库eb service with request. I am unable to get how I can do this.

thanks in advance.


If you need a code sample:

String response = null;

    httppost = new HttpPost(URL_STRING);
    httppost.setParams(httpParams);

    String s = your_XML_Data_As_String_Or_JSON_Or_Whatever;

    try {

        StringEntity entity = new StringEntity(s);
        httppost.setEntity(entity);
        httppost.addHeader("Content-Type", "SomeMIMEType");

        response = httpclient.execute(httppost, handler);
        } catch (Exception e){
            e.printStackTrace }


You should not send a file through a request, you just convert that file to something you can send over. Here is an example: http://www.ibm.com/developerworks/xml/library/x-xml2jsonphp/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜