/**
* 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 "";
}