码迷,mamicode.com
首页 > 其他好文 > 详细

connection.getResponseCode()!=200

时间:2016-03-02 09:35:44      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

android在网络编程的时候没有执行connection.getResponseCode()!=200

1.用真机测试的时候,电脑必须和手机连同一个局域网。

2.必须开新线程,不放在主线程里面访问。

new Thread(){
public void run() {
Looper.prepare();
try {

URL url=new URL("http://192.168.191.1:8080/movie/servlet/FileServlet");
HttpURLConnection connection=(HttpURLConnection)url.openConnection();
connection.setConnectTimeout(5000);
connection.setRequestMethod("GET");
if (connection.getResponseCode()!=200) {
Log.e("aaa", url.toString());
throw new Exception("URL请求失败!");
}
Log.e("bbb", url.toString());
InputStream inputStream=connection.getInputStream();

result=readData(inputStream, "UTF-8");
} catch (Exception e) {
// TODO: handle exception
}
myhandle.sendEmptyMessage(0x1122);
};
}.start();

connection.getResponseCode()!=200

标签:

原文地址:http://www.cnblogs.com/hxh969012806/p/5233612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!