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/
精彩评论