Python code for hitting a URL

Nov. 17th, 2003 | 05:44 pm
mood: impressed impressed

Here's Python code (tested with Python 2.2) for hitting a URL:

---- 8< ----
from httplib import *
conn = HTTPConnection("incq210bc.idc.oracle.com:8888")
conn.request("GET", "/")
resp = conn.getresponse()
print resp.status, resp.reason
data = resp.read()
conn.close()

---- >8 ----

Put this in a for loop if you want to hit it repeatedly. I wrote this in 2 mins. ;-) for testing my servlet. Python is cool.

More httplib examples on Python.org.

#