少年阿賓

          那些青春的歲月

            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 閱讀(815) 評論(0)  編輯  收藏 所屬分類: httpClient
          主站蜘蛛池模板: 南宫市| 石楼县| 诸暨市| 黄浦区| 普格县| 彭山县| 普陀区| 衡山县| 正定县| 大理市| 舟山市| 赤壁市| 岫岩| 武夷山市| 丹江口市| 旬阳县| 鄯善县| 隆林| 佛坪县| 牡丹江市| 河南省| 如东县| 万全县| 读书| 昂仁县| 保山市| 德安县| 辽阳县| 丰原市| 阳朔县| 定南县| 河北省| 仙桃市| 长白| 彭州市| 宁津县| 视频| 铁力市| 金塔县| 高碑店市| 南康市|