/* * 通过 httpclientget 方法 向服务器中请求数据 */
public String getweb(String username, String userpass, String url) {
String str = "";
StringBuffer sb = new StringBuffer(url);
sb.append("?username=");
sb.append(username);
sb.append("&userpass=");
sb.append(userpass);
HttpGet get = new HttpGet(sb.toString());
HttpParams pare = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(pare, 5000);
HttpConnectionParams.setSoTimeout(pare, 5000);
HttpClient client = new DefaultHttpClient();
try {
HttpResponse res = client.execute(get);
if (res.getStatusLine().getStatusCode() == 200) {
HttpEntity enti = res.getEntity();
str = EntityUtils.toString(enti, "utf-8");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(); }
return str;
}
/* * 判断网络是否连接 */
public class NetWorkUtil {
public static final String LOGIN_URL = "http://101.200.142.201:8080/tqyb/login";
public static boolean isNetAvailable(Context context){
//获得网络管理器
ConnectivityManager connM =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = connM.getActiveNetworkInfo();//得到网络详情
if(netInfo == null || !netInfo.isAvailable())
return false;
return true;
}