[color=darkred] 目的:用户输入账号和密码后,根据客户端连接服务器,登陆成功为1,不成功为0。
//根据具体的url连接获得数据
public static String queryStringForPost(String url){
HttpPost request = HttpUtil.getHttpPost(url);
String result = null;
try {
HttpResponse response = HttpUtil.getHttpResponse(request);//这行发生了异常
if(response.getStatusLine().getStatusCode()==200){
result = EntityUtils.toString(response.getEntity());
return result;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
result = "网络异常!";
return result;
} catch (IOException e) {
e.printStackTrace();
result = "网络异常!";
return result;
}
return null;
}
//异常的方法
public static HttpResponse getHttpResponse(HttpPost request) throws ClientProtocolException, IOException{
HttpResponse response = new DefaultHttpClient().execute(request);
return response;
}[/color]