Quickies

[categories] [index] [all (527)] [latest]

Python
  1. #!/usr/bin/python
    
    import httplib
    
    def headers_and_contents(host, path, headers):
    
        conn = httplib.HTTPConnection(host)
        conn.request("GET", path, None, headers)
        r = conn.getresponse()
    
        if r.status != 200:
            print r.status, r.reason
    
        h = r.getheaders()
        s = r.read()
    
        conn.close()
    
        return (h, s)
    
    headers = {"Cookie" : "key=value;"}
    
    (h, s) = headers_and_contents("www.apple.com", "/index.html", headers)