diff --git a/src/net/oschina/git/utils/HttpUtil.java b/src/net/oschina/git/utils/HttpUtil.java index 00257eb1e8bfcbb07609189e58f992ffd7e35f6f..ff118355e90692e2e70b574d81d5a8b959471110 100644 --- a/src/net/oschina/git/utils/HttpUtil.java +++ b/src/net/oschina/git/utils/HttpUtil.java @@ -36,17 +36,20 @@ public class HttpUtil { header.put("User-Agent", "CC/1.0-$EC"); } } - public static String post(String url,List params,Shell shell) throws ConnectTimeoutException, ClientProtocolException, IOException{ - HttpPost hp = new HttpPost(url); +public static String post(String url, List params, Shell shell) + throws ConnectTimeoutException, ClientProtocolException, IOException { + HttpPost hp = new HttpPost(url); HttpResponse response = null; - for(String st:header.keySet()){ - hp.setHeader(st, header.get(st)); + for (String st : getDefaultHeaders().keySet()) { + hp.setHeader(st, getDefaultHeaders().get(st)); + } + HttpEntity entity = new UrlEncodedFormEntity(params, "utf-8"); + hp.setEntity(entity); + try (CloseableHttpClient httpClient = getHttpClient()) { + response = httpClient.execute(hp); + String responseHtml = EntityUtils.toString(response.getEntity()); + return responseHtml; } - HttpEntity entity = new UrlEncodedFormEntity(params, "utf-8"); - hp.setEntity(entity); - response = httpclient.execute(hp); - String responseHtml = EntityUtils.toString(response.getEntity()); - return responseHtml; } public static String get(String url) throws ClientProtocolException, IOException{ HttpGet hg = new HttpGet(url);