欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android發(fā)送xml數(shù)據(jù)給服務(wù)器的方法

 更新時(shí)間:2015年09月21日 12:17:35   作者:Ruthless  
這篇文章主要介紹了Android發(fā)送xml數(shù)據(jù)給服務(wù)器的方法,以實(shí)例形式較為詳細(xì)的分析了Android發(fā)送XML數(shù)據(jù)及接收XML數(shù)據(jù)的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Android發(fā)送xml數(shù)據(jù)給服務(wù)器的方法。分享給大家供大家參考。具體如下:

一、發(fā)送xml數(shù)據(jù):

public static void main(String[] args) throws Exception {
 String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><videos><video><title>中國(guó)</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);
 //指定發(fā)送的內(nèi)容類型為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("發(fā)送成功");
 }else{
  System.out.println("發(fā)送失敗");
 }
}

二、接受xml數(shù)據(jù):

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");
}

希望本文所述對(duì)大家的Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論