少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks
            /** 
               * HTTP DELETE方法進行刪除操作 
               * @param url 
               * @param map 
               * @return 
               * @throws ClientProtocolException 
               * @throws IOException 
               */  
              public static String remoteDelete(String url, Map<String, String> map) throws ClientProtocolException, IOException{  
                  url = JETSUM_PLATFORM_SERVER+url;  
                  HttpClient httpclient = new DefaultHttpClient();  
                  HttpDelete httpdelete= new HttpDelete();  
                  List<NameValuePair> formparams = setHttpParams(map);  
                  String param = URLEncodedUtils.format(formparams, "UTF-8");  
                  httpdelete.setURI(URI.create(url + "?" + param));  
                  HttpResponse response = httpclient.execute(httpdelete);  
                  String httpEntityContent = GetHttpEntityContent(response);  
                  httpdelete.abort();  
                  return httpEntityContent;     
              }       




             /** 
               * 設置請求參數 
               * @param map 
               * @return 
               */  
              private static List<NameValuePair> setHttpParams(Map<String, String> map) {  
                  List<NameValuePair> formparams = new ArrayList<NameValuePair>();  
                  Set<Map.Entry<String, String>> set = map.entrySet();  
                  for (Map.Entry<String, String> entry : set) {  
                      formparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));  
                  }  
                  return formparams;  
              }  



           /** 
               * 獲得響應HTTP實體內容 
               * @param response 
               * @return 
               * @throws IOException 
               * @throws UnsupportedEncodingException 
               */  
              private static String GetHttpEntityContent(HttpResponse response)  
                      throws IOException, UnsupportedEncodingException {  
                  HttpEntity entity = response.getEntity();  
                  if (entity != null) {  
                      InputStream is = entity.getContent();  
                      BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));  
                      String line = br.readLine();  
                      StringBuilder sb = new StringBuilder();  
                      while (line != null) {  
                          sb.append(line + "\n");  
                          line = br.readLine();  
                      }  
                      return sb.toString();  
                  }  
                  return "";  
              }  
          posted on 2013-04-20 00:54 abin 閱讀(819) 評論(0)  編輯  收藏 所屬分類: httpClient
          主站蜘蛛池模板: 新泰市| 德昌县| 古蔺县| 沅陵县| 长顺县| 靖江市| 乐亭县| 嘉祥县| 叙永县| 长子县| 政和县| 资阳市| 香格里拉县| 株洲县| 宜宾县| 商南县| 体育| 方正县| 故城县| 来安县| 乌拉特中旗| 舒城县| 宝山区| 台南市| 大埔区| 册亨县| 那曲县| 辰溪县| 苏尼特左旗| 吉木乃县| 平罗县| 昭平县| 交口县| 宝兴县| 巴里| 博野县| 贵港市| 花莲市| 平潭县| 南平市| 华容县|