1 InputStream is = new URL("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=" + ip").openStream(); 
2 BufferedReader rd = new BufferedReader(InputStreamReader(is, Charset.forName("UTF-8"))); 

 上图可能出现 超时的情况。

 1 URL url = new URL("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=" + ip);
 2 HttpURLConnection htpcon = (HttpURLConnection) url.openConnection();
 3 htpcon.setRequestMethod("GET");
 4 htpcon.setDoOutput(true);
 5 htpcon.setDoInput(true);
 6 htpcon.setUseCaches(false);
 7 htpcon.setConnectTimeout(1000);
 8 htpcon.setReadTimeout(1000);
 9 InputStream in = htpcon.getInputStream();
10 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));

 

其实url的openStream就是把openConnection和getInputStream连起来调用了。

相关文章:

  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2022-02-12
  • 2021-09-08
  • 2021-08-31
  • 2021-06-06
猜你喜欢
  • 2022-01-01
  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
  • 2021-05-26
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案