当前位置: 移动技术网 > IT编程>移动开发>Android > Android发送xml数据给服务器的方法

Android发送xml数据给服务器的方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

美甲社区门户,帝集团挑战首席花心男,失恋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程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网