少年阿賓

          那些青春的歲月

            BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(22)

          我參與的團(tuán)隊(duì)

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

            /** 
               * HTTP DELETE方法進(jìn)行刪除操作 
               * @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;     
              }       




             /** 
               * 設(shè)置請(qǐng)求參數(shù) 
               * @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;  
              }  



           /** 
               * 獲得響應(yīng)HTTP實(shí)體內(nèi)容 
               * @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) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): httpClient
          主站蜘蛛池模板: 临海市| 调兵山市| 通化市| 平湖市| 海口市| 余姚市| 左权县| 犍为县| 呼伦贝尔市| 屯留县| 陆良县| 黔南| 布尔津县| 江都市| 丽水市| 金川县| 武宣县| 博白县| 都江堰市| 志丹县| 双峰县| 资源县| 全椒县| 东海县| 莎车县| 旬邑县| 宜都市| 定远县| 温泉县| 常熟市| 措美县| 房山区| 康定县| 城步| 和平县| 台湾省| 阳城县| 法库县| 林周县| 荔波县| 庆城县|