收藏
回答

微信小程序码接口经常超时,read/connect Timed out

小程序码获取接口经常超时https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=%s每天有几百次超时, 20000次左右调用,大概有不足500的超时 调用相关代码

SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
simpleClientHttpRequestFactory.setConnectTimeout(3000);
simpleClientHttpRequestFactory.setReadTimeout(6000);

RestTemplate restTemplate = new RestTemplate(new BufferingClientHttpRequestFactory(simpleClientHttpRequestFactory)) ;

String url=String.format(settings.getWXaCodeUnlimit(), token);
Map<String, Object> param = new HashMap<>();
param.put("scene", sceneStr);
param.put("page", page);
param.put("width", 160);
param.put("auto_color", false);
Map<String,Object> lineColor = new HashMap<>();
lineColor.put("r", 0);
lineColor.put("g", 0);
lineColor.put("b", 0);
param.put("line_color", lineColor);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);

HttpEntity requestEntity = new HttpEntity(param, headers);
ResponseEntity<byte[]> entity = null;
entity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, byte[].class);


异常堆栈情况

java.net.SocketTimeoutException: connect timed out

        at java.net.PlainSocketImpl.socketConnect(Native Method)

        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)

        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)

        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)

        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)

        at java.net.Socket.connect(Socket.java:589)

        at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)

        at sun.net.NetworkClient.doConnect(NetworkClient.java:175)

        at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)

        at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)

        at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)

        at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)

        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)

        at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1104)

        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:998)

        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)

        at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)

        at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:80)

        at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)

        at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)

        at org.springframework.http.client.BufferingClientHttpRequestWrapper.executeInternal(BufferingClientHttpRequestWrapper.java:56)

        at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)

        at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)

        at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:93)


最后一次编辑于  2019-04-29
回答关注问题邀请回答
收藏

2 个回答

  • 寂
    2019-04-30

    看起来是网络质量不过关,建议使用腾讯云 :)

    2019-04-30
    有用
    回复
  • 2019-04-30

    求回复

    2019-04-30
    有用
    回复 8
    • Mr.Zhao
      Mr.Zhao
      2019-04-30

      你那超时时间是不是有点短啊

      2019-04-30
      回复
    • 2019-04-30回复Mr.Zhao

      不断了吧,一共9s呢,时间太长没有意义了,可能调用方就提前中断了

      2019-04-30
      回复
    • Mr.Zhao
      Mr.Zhao
      2019-04-30回复
      setConnectTimeout你这个只有三秒啊
      2019-04-30
      回复
    • Mr.Zhao
      Mr.Zhao
      2019-04-30回复
      setConnectTimeout超过三秒报connect time out.。
      setReadTimeout超过六秒报read time out。你把报错的请求时间都打印出来

      2019-04-30
      回复
    • 2019-04-30回复Mr.Zhao

      这个是tcp的连接超时时间吧 3s都没连接上,基本完蛋了吧

      2019-04-30
      回复
    查看更多(3)
登录 后发表内容