HttpURLConnection应用
manifests 注册添加权限
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
- [x] 1.从网络上获取数据 String path ="http://169.254.135.196:8080/aa.json";
- [x] 2.创建url对象 URL url = new URL(path);
- [x] 3.打开一个连接 HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
- [x] 4.设置它的请求方式 urlConnection.setRequestMethod("GET");
- [x] 5.设置它的请求超时时间 urlConnection.setConnectTimeout(5000);
- [x] 6.获得响应码 int code = urlConnection.getResponseCode();
- [x] 7.if(code==200){urlConnection.getintputstrem}获取数据流