国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android發送xml數據給服務器的方法

2020-04-11 11:25:45
字體:
來源:轉載
供稿:網友

本文實例講述了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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 隆尧县| 凤冈县| 郑州市| 江门市| 白水县| 平陆县| 六安市| 江孜县| 宝清县| 鄂温| 焉耆| 德州市| 万宁市| 德昌县| 赫章县| 芦溪县| 徐汇区| 三门县| 邵阳市| 兴海县| 邵东县| 延庆县| 六枝特区| 万盛区| 疏勒县| 三河市| 天门市| 闽清县| 德保县| 微山县| 泰宁县| 巴彦淖尔市| 泰宁县| 江孜县| 临泉县| 罗甸县| 平昌县| 沧源| 阿尔山市| 永寿县| 长子县|