public static void newUrl(Context context, final String path, final NetWorkPort fie){ if(IsNetWork.isConn(context)){ Toast.makeText(context,"网络已连接",Toast.LENGTH_SHORT).show(); AsyncTask<Void,Void,String> as=new AsyncTask<Void, Void, String>() { @Override protected void onPostExecute(String s) { fie.port(s); } @Override protected String doInBackground(Void... voids) { try { URL url=new URL(path); HttpURLConnection connection= (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setConnectTimeout(5000); connection.setReadTimeout(5000); int rs = connection.getResponseCode(); if(rs==200){} InputStream stream = connection.getInputStream(); BufferedReader bu=new BufferedReader(new InputStreamReader(stream,"utf-8")); String st; StringBuffer sb=new StringBuffer(); while ((st=bu.readLine())!=null){ sb.append(st); } bu.close(); return sb.toString(); } catch (Exception e) { e.printStackTrace(); } return null; } }; as.execute(); }else{ IsNeiWork.showNoNetWorkDlg(context); } }
网络[计][通信] network Http url网络解析
最新推荐文章于 2023-03-28 18:19:55 发布