From a3a7d5b7dc1f4a9120b58ae32091d12586a8f674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E4=B8=B9?= <13207025+actri_tdan_admin@user.noreply.gitee.com> Date: Fri, 28 Jul 2023 08:27:36 +0000 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E6=96=B0=E7=9A=84=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 田丹 <13207025+actri_tdan_admin@user.noreply.gitee.com> --- src/net/oschina/git/utils/HttpUtil.java | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/net/oschina/git/utils/HttpUtil.java b/src/net/oschina/git/utils/HttpUtil.java index 00257eb..ff11835 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); -- Gitee