JAVA后台登陆连接超时
发布于 7 年前 作者 fmeng 14126 次浏览 来自 问答
  • 当前 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 回复

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

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();
        }
    }
回到顶部