September 11, 2008

Python vs. Java - HTTP GET Request Complexity

Wow.. talk about programming with a ball and chain on! Some languages just take so much code to do a simple thing.

The following 2 programs each do an HTTP GET and print the contents of the URL.

In Java:


public class JGet {
    public static void main (String[] args) throws IOException {
        try {
            URL url = new URL("");
            BufferedReader in = 
                new BufferedReader(new InputStreamReader(url.openStream()));
            String str;

            while ((str = in.readLine()) != null) {

        catch (MalformedURLException e) {} 
        catch (IOException e) {}

Equivalent in Python:

import urllib
print urllib.urlopen('').read()
Post a Comment