Download our e-book of Introduction To Python
Vish Purohit
4 years ago
from urllib3 import HTTPConnectionPool
pool = HTTPConnectionPool('ajax.googleapis.com', maxsize=1)
r = pool.request('GET', '/ajax/services/search/web',fields={'q': 'python', 'v': '1.0'})
print('Response Status:', r.status)
# Header of the response
print('Header: ',r.headers['content-type'])
# Content of the response
print('Python: ',len(r.data))
r = pool.request('GET', '/ajax/services/search/web',fields={'q': 'php', 'v': '1.0'})
# Content of the response
print('php: ',len(r.data))
print('Number of Connections: ',pool.num_connections)
print('Number of requests: ',pool.num_requests)
Response Status: 200
Header: text/javascript; charset=utf-8
Python: 211
php: 211
Number of Connections: 1
Number of requests: 2