JAVA后台登陆连接超时

发布于 8 年前作者 fmeng14213 次浏览最后编辑 8 年前来自 ask
  • 当前 Bug 的表现(可附上截图)

  • 预期表现

  • 复现路径

  • 提供一个最简复现 Demo

java调用小程序报错如下: I/O error on GET request for “https://api.weixin.qq.com/sns/jscode2session”: Connection timed out: connect

代码如下: public static void main(String[] args) { String url = “https://api.weixin.qq.com/sns/jscode2session?appid=appid&secret=secret&js_code=js_code&grant_type=authorization_code”; RestTemplate restTemplate = new RestTemplate(); //进行网络请求,访问url接口    ResponseEntity

responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, String.class);    if(responseEntity != null && responseEntity.getStatusCode() == HttpStatus.OK) {     String sessionData = responseEntity.getBody();    } }

1 回复
syao
syao1 楼6 年前

上面代码无格式,补充代码

public static void main(String[] args) {
        String url = "https://api.weixin.qq.com/sns/jscode2session?appid=appid&secret=secret&js_code=js_code&grant_type=authorization_code";
        RestTemplate restTemplate = new RestTemplate();
        //进行网络请求,访问url接口
        ResponseEntity<String>  responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, String.class);
        if(responseEntity != null && responseEntity.getStatusCode() == HttpStatus.OK) {
            String sessionData = responseEntity.getBody();
        }
    }