//创建访问的方法 public String Check_json(){ //创建一个结果字符串 String result=""; //拼接字符串 StringBuffer sb=new StringBuffer(PICTURE_URL); //创建Url try { URL url=new URL(sb.toString()); //打开连接 HttpURLConnection connection; try { connection = (HttpURLConnection) url.openConnection(); //设置连接的时间 connection.setConnectTimeout(5*1000); connection.setReadTimeout(5*1000); if(connection.getResponseCode()==200){ BufferedReader br=new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8")); //读取每行 result=br.readLine(); } } catch (IOException e1) { e1.printStackTrace(); } } catch (MalformedURLException e) { e.printStackTrace(); } return result; }
时间: 2024-10-20 18:20:41