Python使用GET方法发送HTTP请求源码,pythonget,如下的python源码为


如下的python源码为Python使用GET方法发送HTTP请求源码。

另有HEAD/POST方法发送HTTP请求源码,请关注相关文章:
(1)Python HEAD方法发送HTTP请求源码
(2)Python POST方法发送HTTP请求操作源码

GET方法源码如下:

>>> import httplib  >>> conn = httplib.HTTPConnection("www.python.org")  >>> conn.request("GET", "/index.html")  >>> r1 = conn.getresponse()  >>> print r1.status, r1.reason  200 OK  >>> data1 = r1.read()  >>> conn.request("GET", "/parrot.spam")  >>> r2 = conn.getresponse()  >>> print r2.status, r2.reason  404 Not Found  >>> data2 = r2.read()  >>> conn.close()#www.iplaypy.com 

编橙之家文章,

评论关闭