![Android 开发工具类 30_sendXML Android 开发工具类 30_sendXML](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
String xml = "<?xml version=\"1.0" encoding=\"UTF-8"?>
<persons><person id=\"23\"><name>hello</name><age>30
</age></person></persons>";
private static boolean sendXML(String path, String xml) throws Exception{
//
byte[] data = xml.getBytes(); HttpURLConnection conn = (HttpURLConnection) new URL(path).openConnection();
conn.setConnectTimeout(5000);
conn.setRequestMethod("POST");
conn.setDoOutput(true);//允许对外传输数据
conn.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
conn.setRequestProperty("Content-Length", String.valueOf(data.length)); OutputStream outStream = conn.getOutputStream();
outStream.write(data);
outStream.flush();
outStream.close(); if(conn.getResponseCode() == 200){
return true;
}
return false;
}