File: http_cli_20.py

package info (click to toggle)
m2crypto 0.46.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,952 kB
  • sloc: python: 22,921; makefile: 213; ansic: 94; sh: 17
file content (24 lines) | stat: -rw-r--r-- 510 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import httplib, sys


def test_httplib():
    h = httplib.HTTPConnection("127.0.0.1", 80)
    h.set_debuglevel(1)
    h.putrequest("GET", "/")
    h.putheader("Accept", "text/html")
    h.putheader("Accept", "text/plain")
    h.putheader("Connection", "close")
    h.endheaders()
    resp = h.getresponse()
    f = resp.fp
    while 1:
        data = f.readline()
        if not data:
            break
        sys.stdout.write(data)
    f.close()
    h.close()


if __name__ == "__main__":
    test_httplib()