本文实例讲述了AndroID发送xml数据给服务器的方法。分享给大家供大家参考。具体如下:@H_403_1@
一、发送xml数据:@H_403_1@
public static voID main(String[] args) throws Exception { String xml = "<?xml version=\"1.0\" enCoding=\"UTF-8\"?><vIDeos><vIDeo><Title>中国</Title></vIDeo></vIDeos>"; String path = http://localhost:8083/vIDeoweb/vIDeo/manage.do?method=getXML ; byte[] entity = xml.getBytes("UTF-8"); httpURLConnection conn = (httpURLConnection) new URL(path).openConnection(); conn.setConnectTimeout(5000); conn.setRequestMethod("POST"); conn.setDoOutput(true); //指定发送的内容类型为xml conn.setRequestProperty("Content-Type","text/xml; charset=UTF-8"); conn.setRequestProperty("Content-Length",String.valueOf(entity.length)); OutputStream outStream = conn.getoutputStream(); outStream.write(entity); if(conn.getResponseCode() == 200){ System.out.println("发送成功"); }else{ System.out.println("发送失败"); }}
二、接受xml数据:@H_403_1@
public ActionForward getXML(ActionMapPing mapPing,ActionForm form,httpServletRequest request,httpServletResponse response) throws Exception { inputStream inStream = request.getinputStream(); byte[] data = StreamTool.read(inStream); String xml = new String(data,"UTF-8"); System.out.println(xml); return mapPing.findForward("result");}
希望本文所述对大家的AndroID程序设计有所帮助。@H_403_1@ 总结
以上是内存溢出为你收集整理的Android发送xml数据给服务器的方法全部内容,希望文章能够帮你解决Android发送xml数据给服务器的方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)