首页 新闻 会员 周边 捐助

android 访问https问题

0
悬赏园豆:50 [已解决问题] 解决于 2014-04-15 12:37
 
HttpClient httpClient = getClient(); HttpResponse httpResponse; HttpPost httpPost = new HttpPost("http://115.28.144.252:8977/api.aspx"); List <NameValuePair> nvps = new ArrayList <NameValuePair>(); nvps.add(new BasicNameValuePair("req", "72")); try{ httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); httpResponse = new DefaultHttpClient().execute(httpPost); HttpEntity entity = httpResponse.getEntity(); String strRet = EntityUtils.toString(entity); int responseCode = httpResponse.getStatusLine().getStatusCode(); String message = httpResponse.getStatusLine().getReasonPhrase(); if (responseCode == 200 && entity != null) { str = strRet; } else{ str = "Error Response: "+message; } }




//GetClient方法
public
HttpClient getClient() { BasicHttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(params, true); SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schReg.register(new Scheme("https", SSLTrustAllSocketFactory.getSocketFactory(), 443)); ClientConnectionManager connMgr = new ThreadSafeClientConnManager(params, schReg); return new DefaultHttpClient(connMgr, params); }

主要代码,每次执行到excute时候就抛出异常。但是异常没有消息  求指点

_10Buns的主页 _10Buns | 初学一级 | 园豆:113
提问于:2014-04-15 09:17
< >
分享
最佳答案
0

新版本sdk访问http需要开新线程, 疏忽了

_10Buns | 初学一级 |园豆:113 | 2014-04-15 12:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册