美甲社区门户,帝集团挑战首席花心男,失恋33天mp4
本文实例讲述了android发送xml数据给服务器的方法。分享给大家供大家参考。具体如下:
一、发送xml数据:
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数据:
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 studio开发小型对话机器人app(实例代码)
Android通过Java sdk的方式接入OpenCv的方法
Android 通过cmake的方式接入opencv的方法步骤
Android Studio finish()方法的使用与解决app点击“返回”(直接退出)
Android 进度条 ProgressBar的实现代码(隐藏、出现、加载进度)
网友评论