How can I read an ASP page from my Java code?
Created May 4, 2012
I have found that Microsoft's IIS web server requires a full URL in the GET command - not just a path. This is something you have to watch out for if you are accessing URLs directly from a Socket. However, if you are using URLConnection, this seems to be done properly for you. So your problem in this case is probably a typo in the URL you are entering, or something of that sort.
For example, running the following program using the command:
java URLReader http://www.microsoft.com/windows2000/ downloads/recommended/sp1/default.aspwill correctly return the contents of the specified ASP page.
import java.net.*; import java.io.*; public class URLReader { public static void main(String[] args) { try { URL url = new URL(args[0]); URLConnection con = url.openConnection(); BufferedReader in = new BufferedReader( new InputStreamReader( con.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); } catch (Exception e) { System.err.println(e.getMessage()); } } }