From c95cca27d5cadc1fcbd46a943ef67b9db8691d94 Mon Sep 17 00:00:00 2001 From: Allen Date: Fri, 17 Aug 2018 21:47:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/hotlcc/wechat4j/Wechat.java | 17 +---------------- .../com/hotlcc/wechat4j/api/WebWeixinApi.java | 1 + 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/hotlcc/wechat4j/Wechat.java b/src/main/java/com/hotlcc/wechat4j/Wechat.java index b88a36a..d03860c 100644 --- a/src/main/java/com/hotlcc/wechat4j/Wechat.java +++ b/src/main/java/com/hotlcc/wechat4j/Wechat.java @@ -14,13 +14,10 @@ import com.hotlcc.wechat4j.util.*; import org.apache.http.HttpException; import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; -import org.apache.http.HttpResponse; import org.apache.http.client.CookieStore; import org.apache.http.client.HttpClient; -import org.apache.http.conn.ConnectionKeepAliveStrategy; import org.apache.http.cookie.Cookie; import org.apache.http.impl.client.BasicCookieStore; -import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy; import org.apache.http.impl.client.HttpClients; import org.apache.http.protocol.HttpContext; import org.slf4j.Logger; @@ -154,17 +151,6 @@ public class Wechat { } private HttpClient buildHttpClient(CookieStore cookieStore) { - ConnectionKeepAliveStrategy keepAliveStrategy = new DefaultConnectionKeepAliveStrategy() { - @Override - public long getKeepAliveDuration(HttpResponse response, HttpContext context) { - long keepAlive = super.getKeepAliveDuration(response, context); - if (keepAlive == -1) { - //如果服务器没有设置keep-alive这个参数,我们就把它设置成1分钟 - keepAlive = 60000; - } - return keepAlive; - } - }; HttpRequestInterceptor interceptor = new HttpRequestInterceptor() { @Override public void process(HttpRequest httpRequest, HttpContext httpContext) throws HttpException, IOException { @@ -173,7 +159,6 @@ public class Wechat { }; HttpClient httpClient = HttpClients.custom() .setDefaultCookieStore(cookieStore) -// .setKeepAliveStrategy(keepAliveStrategy) .addInterceptorFirst(interceptor) .build(); return httpClient; @@ -641,7 +626,7 @@ public class Wechat { try { JSONObject result = webWeixinApi.syncCheck(httpClient, urlVersion, new BaseRequest(wxsid, skey, wxuin), getSyncKeyList(false)); - logger.debug("微信同步监听心跳返回数据:{}", result); + logger.info("微信同步监听心跳返回数据:{}", result); if (result == null) { throw new RuntimeException("微信API调用异常"); } else { diff --git a/src/main/java/com/hotlcc/wechat4j/api/WebWeixinApi.java b/src/main/java/com/hotlcc/wechat4j/api/WebWeixinApi.java index e6ecc81..4ede037 100644 --- a/src/main/java/com/hotlcc/wechat4j/api/WebWeixinApi.java +++ b/src/main/java/com/hotlcc/wechat4j/api/WebWeixinApi.java @@ -409,6 +409,7 @@ public class WebWeixinApi { .setRedirectsEnabled(false) .build(); httpGet.setConfig(config); + httpGet.addHeader("Connection", "Keep-Alive"); HttpResponse response = httpClient.execute(httpGet); int statusCode = response.getStatusLine().getStatusCode();