Android网络请求:HttpURLConnection
把网址封装成一个URL对象:
URL url = new URL(path);//path 为网络请求的地址
获取客户端和服务器的连接对象(这个时候还没建立连接):
HttpURLConnection con = (HttpURLConnection) url.openConnection();
对连接对象进行初始化:
con.setRequestMethod("GET");
con.setConnectTimeout(5000);
con.setReadTimeout(5000);
con.connect();
if (con.getResponseCode() == 200) {
//当请求成功后做些事情。。。
}