首页 新闻 会员 周边

android获取远程数据获取不到

0
悬赏园豆:10 [已解决问题] 解决于 2015-05-07 16:02

public void onClick(View v) {

TextView tv_1 = (TextView) findViewById(R.id.tv1);
String httpUrl = "http://www.517yueye.com/android.aspx";
HttpGet httpRequest = new HttpGet(httpUrl);
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpResp /> // 请求成功
if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
// 取得返回的字符串
String strResult = EntityUtils.toString(httpResponse
.getEntity());
tv_1.setText(strResult);  //问题就是这里取不到数据
} else {
tv_1.setText("请求错误!");
}

} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {

e.printStackTrace();
}

}

问题补充:

不报错,但就是取不到远程的值,很奇怪。

jason2013的主页 jason2013 | 小虾三级 | 园豆:1998
提问于:2015-05-06 15:16
< >
分享
最佳答案
0

把HttpResponse httpResp改为HttpResponse httpResp= httpClient.execute(httpRequest );看有用没?

收获园豆:10
雾海中的那粟光 | 初学一级 |园豆:114 | 2015-05-07 13:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册