------------(HttpCilent)---------------------------------(get请求)---------------------------------------------------------------------------------
添加网络权限:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
----------------------------------------------------------------------------------------------------------------------------------------------------------
依赖(必要)
android {
useLibrary 'org.apache.http.legacy'
}
----------------------------------------------------------------------------------------------------------------------------------------------------------
public String HttpClient(){ DefaultHttpClient httpClient = new DefaultHttpClient(); String path="http://www.93.gov.cn/93app/data.do?channelId=0&startNum=0"; HttpGet get = new HttpGet(path); try { HttpResponse httpResponse = httpClient.execute(get); StatusLine line = httpResponse.getStatusLine(); int code = line.getStatusCode(); if (code==200){ HttpEntity entity = httpResponse.getEntity(); InputStream inputStream = entity.getContent(); byte[] buf=new byte[1024]; int len=0; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); while ((len=inputStream.read(buf))!=-1){ outputStream.write(buf,0,len); s = outputStream.toString(); } Log.i("s",s); return s; } } catch (Exception e) { e.printStackTrace(); } return null; }------------------------------------------------------------------------------------