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


Java HttpGet.abort方法代码示例

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


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

示例1: getText

import org.apache.http.client.methods.HttpGet; //导入方法依赖的package包/类
public static String getText(String redirectLocation) {
    HttpGet httpget = new HttpGet(redirectLocation);
    // Create a response handler
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = "";
    try {
        responseBody = httpclient.execute(httpget, responseHandler);
    } catch (Exception e) {
        e.printStackTrace();
        responseBody = null;
    } finally {
        httpget.abort();
        // httpclient.getConnectionManager().shutdown();
    }
    return responseBody;
}
 
开发者ID:bluetata,项目名称:crawler-jsoup-maven,代码行数:17,代码来源:CSDNLoginApater.java

示例2: doGet

import org.apache.http.client.methods.HttpGet; //导入方法依赖的package包/类
/**
 * HTTP Get 获取内容
 *
 * @param url     请求的url地址 ?之前的地址
 * @param params  请求的参数
 * @param charset 编码格式
 * @return 页面内容
 */
public static String doGet(String url, Map<String, String> params, String charset) throws Exception {
    if (StringUtils.isBlank(url)) {
        return null;
    }
    try {
        if (params != null && !params.isEmpty()) {
            List<NameValuePair> pairs = new ArrayList<NameValuePair>(params.size());
            for (Map.Entry<String, String> entry : params.entrySet()) {
                String value = entry.getValue();
                if (value != null) {
                    pairs.add(new BasicNameValuePair(entry.getKey(), value));
                }
            }
            url += "?" + EntityUtils.toString(new UrlEncodedFormEntity(pairs, charset));
        }
        HttpGet httpGet = new HttpGet(url);
        CloseableHttpResponse response = httpClient.execute(httpGet);
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 200) {
            httpGet.abort();
            throw new RuntimeException("HttpClient,error status code :" + statusCode);
        }
        HttpEntity entity = response.getEntity();
        String result = null;
        if (entity != null) {
            result = EntityUtils.toString(entity, "utf-8");
        }
        EntityUtils.consume(entity);
        response.close();
        return result;
    } catch (Exception e) {
        throw e;
    }
}
 
开发者ID:fanqinghui,项目名称:wish-pay,代码行数:43,代码来源:HttpClientUtils.java

示例3: doHttpGet

import org.apache.http.client.methods.HttpGet; //导入方法依赖的package包/类
public String doHttpGet(Context context, StatisCacheBean mStatisCacheBean) throws HttpDataConnectionException, HttpDataParserException {
    String str = null;
    if (context != null) {
        if (DataStatistics.getInstance().isDebug()) {
            Log.d(DataStatistics.TAG, "url:" + mStatisCacheBean.getCacheData());
        }
        if (mStatisCacheBean != null) {
            StatisDBHandler.saveLocalCache(context, mStatisCacheBean);
            if (DataUtils.getAvailableNetWorkInfo(context) != null) {
                HttpGet httpGet = new HttpGet(mStatisCacheBean.getCacheData());
                try {
                    HttpResponse httpResponse = this.mDefaultHttpClient.execute(httpGet);
                    if (httpResponse == null) {
                        try {
                            httpGet.abort();
                            this.mDefaultHttpClient.getConnectionManager().closeExpiredConnections();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else {
                        int responseCode = httpResponse.getStatusLine().getStatusCode();
                        if (DataStatistics.getInstance().isDebug()) {
                            Log.d(DataStatistics.TAG, "responseCode:" + responseCode);
                        }
                        if (responseCode < 200 || responseCode >= 300) {
                            if (!DataStatistics.getInstance().isDebug() && (System.currentTimeMillis() - mStatisCacheBean.getCacheTime()) / 1000 >= 432000) {
                                StatisDBHandler.deleteByCacheId(context, mStatisCacheBean.getCacheId());
                            }
                            throw new HttpDataConnectionException(httpResponse.getStatusLine().toString());
                        } else if (httpResponse.getEntity() == null) {
                            try {
                                httpGet.abort();
                                this.mDefaultHttpClient.getConnectionManager().closeExpiredConnections();
                            } catch (Exception e2) {
                                e2.printStackTrace();
                            }
                        } else {
                            str = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
                            if (DataStatistics.getInstance().isDebug()) {
                                Log.d(DataStatistics.TAG, "result:" + str);
                            }
                            StatisDBHandler.deleteByCacheId(context, mStatisCacheBean.getCacheId());
                            try {
                                httpGet.abort();
                                this.mDefaultHttpClient.getConnectionManager().closeExpiredConnections();
                            } catch (Exception e22) {
                                e22.printStackTrace();
                            }
                        }
                    }
                } catch (Exception e222) {
                    e222.printStackTrace();
                    throw new HttpDataParserException(e222);
                } catch (Exception e2222) {
                    e2222.printStackTrace();
                    throw new HttpDataConnectionException(e2222);
                } catch (Exception e22222) {
                    e22222.printStackTrace();
                    throw new HttpDataConnectionException(e22222);
                } catch (Exception e222222) {
                    e222222.printStackTrace();
                    throw new HttpDataConnectionException(e222222);
                } catch (Throwable th) {
                    try {
                        httpGet.abort();
                        this.mDefaultHttpClient.getConnectionManager().closeExpiredConnections();
                    } catch (Exception e2222222) {
                        e2222222.printStackTrace();
                    }
                }
            }
        }
    }
    return str;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:76,代码来源:HttpEngine.java

示例4: run

import org.apache.http.client.methods.HttpGet; //导入方法依赖的package包/类
/**
 * Executes the download in a separate thread
 */
public void run() {
    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

    State state = new State(mInfo, mService);
    AndroidHttpClient client = null;
    PowerManager.WakeLock wakeLock = null;
    int finalStatus = DownloaderService.STATUS_UNKNOWN_ERROR;

    try {
        PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG);
        wakeLock.acquire();

        if (Constants.LOGV) {
            Log.v(Constants.TAG, "initiating download for " + mInfo.mFileName);
            Log.v(Constants.TAG, "  at " + mInfo.mUri);
        }

        client = AndroidHttpClient.newInstance(userAgent(), mContext);

        boolean finished = false;
        while (!finished) {
            if (Constants.LOGV) {
                Log.v(Constants.TAG, "initiating download for " + mInfo.mFileName);
                Log.v(Constants.TAG, "  at " + mInfo.mUri);
            }
            // Set or unset proxy, which may have changed since last GET
            // request.
            // setDefaultProxy() supports null as proxy parameter.
            ConnRouteParams.setDefaultProxy(client.getParams(),
                    getPreferredHttpHost(mContext, state.mRequestUri));
            HttpGet request = new HttpGet(state.mRequestUri);
            try {
                executeDownload(state, client, request);
                finished = true;
            } catch (RetryDownload exc) {
                // fall through
            } finally {
                request.abort();
                request = null;
            }
        }

        if (Constants.LOGV) {
            Log.v(Constants.TAG, "download completed for " + mInfo.mFileName);
            Log.v(Constants.TAG, "  at " + mInfo.mUri);
        }
        finalizeDestinationFile(state);
        finalStatus = DownloaderService.STATUS_SUCCESS;
    } catch (StopRequest error) {
        // remove the cause before printing, in case it contains PII
        Log.w(Constants.TAG,
                "Aborting request for download " + mInfo.mFileName + ": " + error.getMessage());
        error.printStackTrace();
        finalStatus = error.mFinalStatus;
        // fall through to finally block
    } catch (Throwable ex) { // sometimes the socket code throws unchecked
                             // exceptions
        Log.w(Constants.TAG, "Exception for " + mInfo.mFileName + ": " + ex);
        finalStatus = DownloaderService.STATUS_UNKNOWN_ERROR;
        // falls through to the code that reports an error
    } finally {
        if (wakeLock != null) {
            wakeLock.release();
            wakeLock = null;
        }
        if (client != null) {
            client.close();
            client = null;
        }
        cleanupDestination(state, finalStatus);
        notifyDownloadCompleted(finalStatus, state.mCountRetry, state.mRetryAfter,
                state.mRedirectCount, state.mGotData, state.mFilename);
    }
}
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:79,代码来源:DownloadThread.java


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