当前位置: 首页>>代码示例>>Java>>正文


Java DefaultHttpClient.close方法代码示例

本文整理汇总了Java中org.apache.http.impl.client.DefaultHttpClient.close方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultHttpClient.close方法的具体用法?Java DefaultHttpClient.close怎么用?Java DefaultHttpClient.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.impl.client.DefaultHttpClient的用法示例。


在下文中一共展示了DefaultHttpClient.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getToken

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
public AccessTokenDTO getToken(String code) {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    AccessTokenDTO token = null;
    try {
        HttpPost httppost = new HttpPost("https://api.twitch.tv/kraken/oauth2/token" +
                "?client_id=" + Config.getCatalog().twitch.clientId +
                "&client_secret=" + Config.getCatalog().twitch.clientSecret +
                "&code=" + code +
                "&grant_type=authorization_code" +
                "&redirect_uri=" + Config.getCatalog().twitch.redirectUri);

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = httpclient.execute(httppost, responseHandler);

        token = new Gson().fromJson(responseBody, AccessTokenDTO.class);
    } catch (IOException e) {
        TwasiLogger.log.error(e);
    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
        httpclient.close();
    }
    return token;
}
 
开发者ID:Twasi,项目名称:twasi-core,代码行数:27,代码来源:TwitchAPI.java

示例2: callWebProxy

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
public void callWebProxy(String url) {
    String resultCode = "";
    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {
        HttpGet httpget = new HttpGet(url);
        HttpResponse response = httpclient.execute(httpget);

        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == HttpStatus.SC_OK) {
            HttpEntity entity = response.getEntity();
            resultCode = ResponseCode.CALLRESPONSEERROR;
            if (entity != null) {
                String responseString = EntityUtils.toString(entity);
                if (responseString.contains("Spark Jobs") && responseString.contains("Stages")
                        && responseString.contains("Storage") && responseString.contains("Environment")
                        && responseString.contains("Executors")) {
                    resultCode = ResponseCode.CALLSUCCESS;
                }
            }
        } else if (statusCode == HttpStatus.SC_MOVED_TEMPORARILY
                || statusCode == HttpStatus.SC_MOVED_PERMANENTLY) {
            resultCode = ResponseCode.CALLFORBIDDEN;
        } else {
            resultCode = ResponseCode.OTHER_RESPONSE + String.valueOf(statusCode);
        }
    } catch (Exception e) {
        LOG.warn("WebProxyCall exception " + e.getMessage());
        resultCode = ResponseCode.CALLEXCEPTION;
    } finally {
        httpclient.close();
    }
    LOG.info("WebProxyCall result " + resultCode);
    if (!resultCode.equals(ResponseCode.CALLSUCCESS)) {
        System.exit(1);
    }
}
 
开发者ID:aliyun,项目名称:aliyun-cupid-sdk,代码行数:37,代码来源:WebProxyCall.java

示例3: getTwitchAccountByToken

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
public TwitchAccount getTwitchAccountByToken(AccessTokenDTO token) {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    TwitchAccount acc = null;
    try {
        HttpGet httpget = new HttpGet("https://api.twitch.tv/kraken");

        httpget.setHeader("Accept", "application/vnd.twitchtv.v5+json");
        httpget.setHeader("Authorization", "OAuth " + token.getAccessToken());

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = httpclient.execute(httpget, responseHandler);

        TokenInfoDTO info = new Gson().fromJson(responseBody, TokenInfoDTO.class);

        acc = new TwitchAccount(info.getToken().getUserName(), token.toModel(), info.getToken().getUserId(), new ArrayList<>());
        acc.setEmail(info.getToken().getEmail());
    } catch (IOException e) {
        TwasiLogger.log.error(e);
    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
        httpclient.close();
    }
    return acc;
}
 
开发者ID:Twasi,项目名称:twasi-core,代码行数:28,代码来源:TwitchAPI.java

示例4: applyUserInfo

import org.apache.http.impl.client.DefaultHttpClient; //导入方法依赖的package包/类
public void applyUserInfo(TwitchAccount account) {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    TwitchAccount acc = null;
    try {
        HttpGet httpget = new HttpGet("https://api.twitch.tv/kraken/user");

        httpget.setHeader("Accept", "application/vnd.twitchtv.v5+json");
        httpget.setHeader("Authorization", "OAuth " + account.getToken().getAccessToken());

        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = httpclient.execute(httpget, responseHandler);

        System.out.println(responseBody);

        UserInfoDTO info = new Gson().fromJson(responseBody, UserInfoDTO.class);

        account.setEmail(info.getEmail());
    } catch (IOException e) {
        TwasiLogger.log.error(e);
    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
        httpclient.close();
    }
}
 
开发者ID:Twasi,项目名称:twasi-core,代码行数:28,代码来源:TwitchAPI.java


注:本文中的org.apache.http.impl.client.DefaultHttpClient.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。