- #coding=UTF-8
- import httplib
- def url_open(conn_obj):
- """httplib长连接"""
- try:
- #GET方式
- conn_obj.request("GET", "/func?para=0", "", {"Connection":"Keep-Alive"})
- #POST方式
- #conn_obj.request("POST", "/func","param=0", {"Connection":"Keep-Alive"})
- response = conn_obj.getresponse()
- return response.read()
- except:
- return "error"
-
- if __name__ == "__main__":
- conn = httplib.HTTPConnection("12.12.12.12:80")
- for i in range(100):
- print url_open(conn)
- conn.close()
HTTP 1.1协议headers中指定Keep-Alive就额可以了...
使用长连接这样就可以节省很多系统资源.
阅读(5991) | 评论(0) | 转发(0) |