发送对access_token的请求时连接超时

时间:2019-04-18 05:56:55

标签: java line

This is the result of postman sending the request This is the console error message 我用相同的参数在邮递员上请求它,并获得了access_token。但是用代码发送请求是行不通的。我想知道怎么了

Map<String, String> params = new HashMap<>();
    params.put("client_id", CLIENT_ID);
    params.put("client_secret", CLIENT_SECRET);
    params.put("grant_type", "authorization_code");
    params.put("code", code);
    params.put("redirect_uri", REDIRECT_URL);

    HttpPost httpPost = new HttpPost(GET_TOKEN_URL);
    List<NameValuePair> pairList = new ArrayList<>();
    for (String key : params.keySet()) {
        pairList.add(new BasicNameValuePair(key, params.get(key)));
    }

    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(60000).setConnectionRequestTimeout(60000).build();
    httpPost.setConfig(requestConfig);
    UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(pairList);
    httpPost.setEntity(urlEncodedFormEntity);

    try (
            CloseableHttpResponse response = HttpClients.createDefault().execute(httpPost)
    ) {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            throw new RuntimeException("statusCode = " + statusCode);
        } else {
            HttpEntity respEntity = response.getEntity();
            token = EntityUtils.toString(respEntity, "UTF-8");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

处理对{s}-> https://api.line.me:443的请求时捕获到I / O异常(java.net.SocketException):连接重置 重试对{s}-> https://api.line.me:443的请求 处理对{s}-> https://api.line.me:443的请求时捕获到I / O异常(java.net.SocketException):连接重置 重试对{s}-> https://api.line.me:443的请求 处理对{s}-> https://api.line.me:443的请求时捕获到I / O异常(java.net.SocketException):连接重置 重试对{s}-> https://api.line.me:443

的请求

0 个答案:

没有答案