首页 > 移动平台 > 详细

Android 开发工具类 30_sendXML

时间:2015-05-30 21:04:01      阅读:272      评论:0      收藏:0      [点我收藏+]

String xml = "<?xml version=\"1.0" encoding=\"UTF-8"?>

<persons><person id=\"23\"><name>hello</name><age>30

</age></person></persons>";

 1 private static boolean sendXML(String path, String xml) throws Exception{
 2         //  
 3         byte[] data = xml.getBytes();
 4         
 5         HttpURLConnection conn = (HttpURLConnection) new URL(path).openConnection();
 6         conn.setConnectTimeout(5000);
 7         conn.setRequestMethod("POST");
 8         conn.setDoOutput(true);//允许对外传输数据
 9         conn.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
10         conn.setRequestProperty("Content-Length", String.valueOf(data.length));
11         
12         OutputStream outStream = conn.getOutputStream();
13         outStream.write(data);
14         outStream.flush();
15         outStream.close();
16         
17         if(conn.getResponseCode() == 200){
18             return true;
19         }
20         return false;
21     }

 

Android 开发工具类 30_sendXML

原文:http://www.cnblogs.com/renzimu/p/4540888.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!