通过 httpclientget 方法 向服务器中请求数据
2016-05-18 21:11
337 查看
/* * 通过 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;
}
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;
}
相关文章推荐
- httpurlconectiondopost的方法向服务器中获取json文件
- HTTP协议
- Caffe框架源码剖析(1)—构建网络
- 华中农业大学第四届程序设计大赛网络同步赛
- ClassNotFoundException: org.codehaus.xfire.transport.http.XFireConfigurableServlet怎么解决
- Android网络优先级及更改
- 最近笔记3
- http Cache-control
- commons-httpclient 3.x如何按照host单独配置连接数和超时参数
- [BS-23] AFN网络请求上拉/下拉刷新的细节问题总结
- Android批量加载网络图片存在的问题及简单实现
- https://github.com/hehonghui/android-tech-frontier
- 采用ListView实现网络图片的显示
- WebView,HttpURLConnection,HttpClient的简单使用
- 访问jsp报HTTP Status 500 - java.lang.NullPointerException的解决方法
- Android与服务器端通信方式(一)之HTTP、TCP、Socket
- AngularJS $http简介1
- 基础知识(十五)python简单http服务器
- 回归神经网络RNN(Recurrent Neural network)
- 回归神经网络RNN(Recurrent Neural network)