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     }

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。