Android使用HttpURLConnection发送Get请求
2015-03-10 18:00
323 查看
private void getDataByHttp() { String strUrl = "http://192.168.1.113:8080/TestHttp/MyJsp.jsp"; strUrl += "?"; try { strUrl += "userName=" + URLEncoder.encode("测试", "UTF-8"); strUrl += "&userPassword=" + "123456"; System.out.println(strUrl); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } String resultData= ""; URL url = null; try { url = new URL(strUrl); } catch (MalformedURLException e) { e.printStackTrace(); } if(url != null) { HttpURLConnection httpURLConnection = null; try { httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setConnectTimeout(3000); if(httpURLConnection.getResponseCode() != 200) { Log.e("链接失败","返回不是200--" + httpURLConnection.getResponseCode()); Message msg = new Message(); msg.what = 2; handler.sendMessage(msg); return; } InputStream input = httpURLConnection.getInputStream(); InputStreamReader streamReader = new InputStreamReader(input); BufferedReader bufferedReader = new BufferedReader(streamReader); String inputLine = null; while((inputLine = bufferedReader.readLine()) != null) { resultData += inputLine + "\r\n"; } bufferedReader.close(); streamReader.close(); input.close(); httpURLConnection.disconnect(); <span style="white-space:pre"> </span>System.out.println(resultData); } catch (IOException e) { e.printStackTrace(); } } }
相关文章推荐
- Android使用HttpURLConnection向服务器发送post和get请求
- (转)Http学习之使用HttpURLConnection发送post和get请求
- Android使用HttpUrlConnection请求服务器发送数据详解
- Android使用HttpURLConnection发送网络请求(笔记)
- 使用HttpURLConnection发送post和get请求
- Android使用HttpUrlConnection请求服务器发送数据详解
- Android使用HttpURLConnection发送Post请求到服务端
- Android上使用HttpURLConnection发送HTTP请求
- android使用HttpURLConnection发送Post/Get请求
- 使用HttpURLConnection发送post和get请求
- Android 使用HttpURLConnection发送Post/Get请求
- Android中使用HttpURLConnection和HttpClient发送Http请求
- Android中 使用HttpURLConnection实现GET请求
- Http学习之使用HttpURLConnection发送post和get请求 android
- android发送http请求—-URLConnection、HttpURLConnection的使用
- 初学使用HttpURLConnection访问网络之发送GET请求
- Http学习之使用HttpURLConnection发送post和get请求
- Http学习之使用HttpURLConnection发送post和get请求
- 使用HttpURLConnection发送post和get请求
- Http学习之使用HttpURLConnection发送post和get请求