Python vs. Java - HTTP GET Request Complexity
Python vs. Java - HTTP GET Request Complexity
Submitted by noreply@blogger.com (Corey Goldberg) on Thu, 11/09/2008 - 18:57.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:
import java.net.*;
import java.io.*;
public class JGet {
public static void main (String[] args) throws IOException {
try {
URL url = new URL("http://www.google.com");
BufferedReader in =
new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
System.out.println(str);
}
in.close();
}
catch (MalformedURLException e) {}
catch (IOException e) {}
}
}
Equivalent in Python:
import urllib
print urllib.urlopen('http://www.google.com').read()
