def async_fetch(url, headers=None, method="GET", data=None, follow_redirects=False):
"""
Async http fetch
:param url:
:param headers:
:param method:
:param data:
:param follow_redirects:
"""
client = HTTPClient()
headers = headers or {}
body = None
if method == "GET" and data is not None:
url = url + '?' + urlencode(data)
elif method == "POST" and data is not None:
headers.update({'Content-Type': 'application/x-www-form-urlencoded'})
body = urlencode(data)
request = HTTPRequest(url=url, headers=headers,
method=method, follow_redirects=follow_redirects,
body=body)
response = yield client.fetch(request, raise_error=False)
# return response
raise gen.Return(response)
评论列表
文章目录