少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(22)

          我參與的團隊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

            /** 
               * 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 閱讀(823) 評論(0)  編輯  收藏 所屬分類: httpClient
          主站蜘蛛池模板: 滦平县| 大田县| 田林县| 金平| 阿瓦提县| 获嘉县| 连山| 郁南县| 息烽县| 保康县| 云梦县| 梓潼县| 六枝特区| 麻阳| 沾益县| 平罗县| 昆明市| 华阴市| 泸溪县| 海安县| 新竹市| 鲁甸县| 张家界市| 抚松县| 类乌齐县| 蓬溪县| 临漳县| 屏山县| 肥东县| 买车| 诸暨市| 芒康县| 房山区| 丰县| 泗水县| 平果县| 凤庆县| 乌恰县| 凤山市| 中西区| 武威市|