从网上找了段代码,你的app有加网络权限吗?或者如果不行话,你放一段logcat吧
boolean loginState = false;
HttpURLConnection conn = null;
DataInputStream dis = null;
try
{
URL url = new URL(validateUrl);
conn = (HttpURLConnection)url.openConnection();
conn.setConnectTimeout(5000);
conn.setRequestMethod("GET");
conn.connect();
dis = new DataInputStream(conn.getInputStream());
if(conn.getResponseCode() != HttpURLConnection.HTTP_OK)
{
Log.d(this.toString(), "HTTP ERROR");
isNetError = true;
return false;
}
int loginStateInt = dis.read();
Log.v("loginState", String.valueOf(loginStateInt));
if(loginStateInt == 1)
{
loginState = true;
}
}
catch (Exception e)
{
e.printStackTrace();
isNetError = true;
Log.d(this.toString(), e.getMessage() + " 127 line");
}
finally
{
if(conn != null)
{
conn.disconnect();
}
}