瘋狂

          STANDING ON THE SHOULDERS OF GIANTS
          posts - 481, comments - 486, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          httpclient 簡單例子

          Posted on 2010-08-12 19:52 瘋狂 閱讀(1614) 評論(1)  編輯  收藏 所屬分類: java web
          public void doPost(String xml) throws UnsupportedEncodingException{
           
            HttpClient httpclient = new DefaultHttpClient();
            HttpContext localContext = new BasicHttpContext();
            
            List<NameValuePair> qparams = new ArrayList<NameValuePair>();
            qparams.add(new BasicNameValuePair("xmldata", xml));
            HttpPost httppost = new HttpPost(“http://......”);
            httppost.setEntity(new UrlEncodedFormEntity(qparams, HTTP.UTF_8));
            HttpResponse response = null;
            try {
             response = httpclient.execute(httppost, localContext);
             BufferedReader stream = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
             String l ="";
             while ((l=stream.readLine())!=null) {
              System.out.println(l);
             }
            } catch (Exception e) {
             logger.error(e.getMessage());
            }
            httpclient.getConnectionManager().shutdown();
           }
             public final static void main(String[] args) throws Exception {
             
              new HttpClientService().doPost("dopost");
             
             }

          評論

          # re: httpclient 簡單例子  回復  更多評論   

          2014-01-07 14:55 by 地方
          簡單例子
          主站蜘蛛池模板: 松溪县| 松阳县| 凤山市| 丁青县| 化德县| 竹北市| 上思县| 宁波市| 华蓥市| 鲜城| 瓮安县| 吉隆县| 南和县| 张北县| 曲麻莱县| 黑河市| 河津市| 安丘市| 兴和县| 达拉特旗| 苏尼特左旗| 焦作市| 赞皇县| 灵台县| 古蔺县| 蚌埠市| 峨边| 沈丘县| 浦东新区| 蒲江县| 句容市| 扶风县| 苏尼特右旗| 宁夏| 呼伦贝尔市| 榕江县| 玉屏| 黑龙江省| 陆丰市| 临桂县| 苍溪县|