手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >Android发送xml数据给服务器的方法
Android发送xml数据给服务器的方法
摘要:本文实例讲述了Android发送xml数据给服务器的方法。分享给大家供大家参考。具体如下:一、发送xml数据:publicstaticvoi...

本文实例讲述了Android发送xml数据给服务器的方法。分享给大家供大家参考。具体如下:

一、发送xml数据:

public static void main(String[] args) throws Exception { String xml = "<"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数据:

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程序设计有所帮助。

【Android发送xml数据给服务器的方法】相关文章:

android获取网络图片

Android 的Bitmap的修改方法

Android开发笔记之: 数据存储方式详解

Android中隐藏标题栏和状态栏的方法

Android中查看服务是否开启的工具类

Android中获取IMEI码的办法

基于Android中手势交互的实现方法

Android中 动态改变对话框值的方法

android中ListView数据刷新时的同步方法

android ListView自动滚动方法

精品推荐
分类导航