瘋狂

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

          httpclient 簡(jiǎn)單例子

          Posted on 2010-08-12 19:52 瘋狂 閱讀(1613) 評(píng)論(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");
             
             }

          評(píng)論

          # re: httpclient 簡(jiǎn)單例子  回復(fù)  更多評(píng)論   

          2014-01-07 14:55 by 地方
          簡(jiǎn)單例子
          主站蜘蛛池模板: 清水县| 南岸区| 吴忠市| 福建省| 三江| 东乌| 五大连池市| 施秉县| 乡城县| 炎陵县| 梓潼县| 庆云县| 彭州市| 潞西市| 大方县| 抚松县| 清远市| 兴义市| 宜黄县| 临朐县| 黔西县| 上饶县| 常宁市| 达拉特旗| 增城市| 哈尔滨市| 东辽县| 美姑县| 通榆县| 宣恩县| 将乐县| 北川| 廉江市| 丰城市| 宜兰市| 崇仁县| 屯昌县| 同心县| 斗六市| 怀来县| 文登市|