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
will correctly return the contents of the specified ASP page.

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) {
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact