码迷,mamicode.com
首页 > 移动开发 > 详细

Android 开发工具类 30_sendXML

时间:2015-05-30 21:04:13      阅读:157      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!