代码运行到 connection.connect();会报networkonmainthreadexception
URL postUrl = new URL("http://221.214.177.85/bb2/android_login.aspx?name=123&pwd=123");
HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection();
connection.setDoInput(true);
connection.setRequestMethod("GET");
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestProperty("Content-Type","text/xml");
connection.connect();
网址http://221.214.177.85/bb2/android_login.aspx?name=123&pwd=123返回的内容如下:
<?xml version="1.0" encoding="utf-8"?>
<root>
<state>false</state>
<msg>用户名或密码不正确!</msg>
<data></data>
</root>
AVD里面的target是:Android 4.0 -API Level14
------解决方案--------------------
networkonmainthreadexception
就是说你的网络请求不能放在主线程里做,因为网络请求比较耗费时间会造成主线程UI卡顿,所以都是用多线程来处理的。