How can I read an ASP page from my Java code?

Tim Rohaly

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/
will 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(

            String inputLine;
            while ((inputLine = in.readLine()) != null)

        catch (Exception e) {