Comparison: HTTP with Java, Perl or Python

Magnus spammers.do.not.bother at void.bogus
Fri Jun 7 16:59:57 EDT 2002


Ingo Linkweiler wrote:

> Hello,
> 
> for a comparison of languages I need a complete "translation" of this
> short skript into Perl, Tcl and Java:
> 
>  myurl = "http://www.uni-dortmund.de"
>  import urllib
>  file  = urllib.urlopen(myurl)
>  text  = file.read()
>  file.close()
>  print text
> 
> Can you send me some solutions?
> The skripts must be able to run, please do not post "partial" solutions.
> 
> Ingo


Try following...

Regards,
Magnus
--

import java.io.*;
import java.net.*;

public final class UrlGet {

    final public static void main(String args[]) {
 
        try {
            String theContent = new String();
            URL theUrl = new URL("http://www.uni-dortmund.de");
            URLConnection theUrlConnection = theUrl.openConnection();
            BufferedReader theReader =
                new Buffe
redReader(new InputStreamReader(theUrlConnection.getInputStream()));
            String theInputLine;
            while ((theInputLine = theReader.readLine()) != null) {
                theContent += theInputLine;
            }
            theReader.close();
            System.out.println(theContent);
        }
        catch (Exception e){
            System.err.println(e.getMessage());
            System.err.println(e.toString());
            e.printStackTrace();
        }
    }
}




More information about the Python-list mailing list