android httpclient请求问题

/***数据请求**@paramurl*@return*/publicstaticStringqueryStringForPost(Stringurl){//String... /*** 数据请求* * @param url* @return*/public static String queryStringForPost(String url) {// String s_url = "";String realurl = s_url + url;HttpPost request = HttpUtil.getHttpPost(realurl);String result = null;try {HttpResponse response = HttpUtil.getHttpResponse(request);if (response.getStatusLine().getStatusCode() == 200) {result = EntityUtils.toString(response.getEntity());return result;}} catch (ClientProtocolException e) {e.printStackTrace();result = "网络异常!";return result;} catch (IOException e) {e.printStackTrace();result = "网络异常!";return result;} return null;}// 异常的方法public static HttpResponse getHttpResponse(HttpPost request)throws ClientProtocolException, IOException {HttpResponse response = new DefaultHttpClient().execute(request);return response;}/*** 此应用所有网络连接使用一个httpClient* * @return*/private HttpClient createHttpClient() {Log.i(APP, "CREATE HTTPCLIENT");HttpParams httpParams = new BasicHttpParams();HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);HttpProtocolParams.setContentCharset(httpParams,HTTP.DEFAULT_CONTENT_CHARSET);HttpProtocolParams.setUseExpectContinue(httpParams, true);/* 连接超时 */HttpConnectionParams.setConnectionTimeout(httpParams, 1000);/* 请求超时 */HttpConnectionParams.setSoTimeout(httpParams, 4000);SchemeRegistry schemeRegistry = new SchemeRegistry();schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));// 关键代码--事关线程安全。ClientConnectionManager clientConnectionManager = new ThreadSafeClientConnManager(httpParams, schemeRegistry);return new DefaultHttpClient(clientConnectionManager, httpParams);}public HttpClient getHttpClient() {return httpClient;}@Overridepublic void onLowMemory() {super.onLowMemory();shutdownHttpClient();}@Overridepublic void onTerminate() {super.onTerminate();shutdownHttpClient();}private static void shutdownHttpClient() {if (httpClient != null && httpClient.getConnectionManager() != null) {httpClient.getConnectionManager().shutdown();}}我使用的是httpclient请求直接调用web端action方法,是不是数据请求完后自动回释放掉连接,还是每次需要我再调用下shutdownHttpClient()方法。 展开
 我来答
tanwei4199
2012-08-02 · TA获得超过397个赞
知道小有建树答主
回答量:943
采纳率:0%
帮助的人:493万
展开全部
这个是面向连接的,每次使用完了需要shutdown关闭管理器
百度网友7708c308a
2012-08-02
知道答主
回答量:9
采纳率:0%
帮助的人:1.3万
展开全部
有点乱啊~
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式