Android 开发工具类 30_sendXML

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     }
原文地址:https://www.cnblogs.com/renzimu/p/4540888.html