Howdy ho everyone, I am trying to get an HTML page source content from this site: "http://207.200.96.231:8008" using java. However the default libraries of java did not help me in this one. I also tried using this tutorial: http://blog.codehangover.com/read-html-with-java-then-7-fun-things-to-do-to-it/ but it did not work either. I think the problem occurs because of a security protection of the site. Any ideas of how to implement the code? Or are there any libraries that can serve my need?
I also tried this code but it doesn't work with your website, it refuses the connection and it's as you said, security reasons: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; public class Acess { public static void main(String[] args) { String urltext = " http://207.200.96.231:8080 "; BufferedReader in = null; try { URL url = new URL(urltext); in = new BufferedReader(new InputStreamReader(url.openStream())); String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println(inputLine); } } catch (Exception e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
try { URL url = new URL(" http://207.200.96.231:8008/7.html "); HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection(); urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0"); InputStream is = urlConnection.getInputStream(); BufferedInputStream in = new BufferedInputStream(is); int c; while ((c = in.read()) != -1) { System.out.write(c); } urlConnection.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } This code got it working. Shoutcast station wants a user-agent to access its contents and adding the: urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0"); solved my issue. Thanks anyways :)
Ah good then and you're welcome.
Join our real-time social learning platform and learn together with your friends!