public class Util { String str = ""; public String getjson(String strjson){ URL url=null; HttpURLConnection urlConnection=null; try { url=new URL(strjson); urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setConnectTimeout(5000); urlConnection.setReadTimeout(5000); int res = urlConnection.getResponseCode(); if(res==200){ InputStream in = urlConnection.getInputStream(); byte[] b=new byte[1024]; int len=0; while((len=in.read(b))!=-1){ String st=new String(b,0,len); str+=st; } } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return str; } }
使用HttpUUrlConnection网络请求
最新推荐文章于 2024-04-14 10:00:17 发布