问题
What I have now (Python 3.4):
r = yield from aiohttp.request('post', URL, params=None, data=values, headers=headers)
What is in the documentation:
conn = aiohttp.ProxyConnector(proxy="http://some.proxy.com")
r = await aiohttp.get('http://python.org', connector=conn)
So, how should I send a post request with headers through proxy connection with aiohttp?
Thanks.
回答1:
connector = aiohttp.ProxyConnector(proxy="http://some.proxy.com")
session = aiohttp.ClientSession(connector=connector)
async with session.post("http://example.com/post", data=b"binary data") as resp:
print(resp.status)
session.close()
回答2:
you can use this:
import aiohttp
conn = aiohttp.ProxyConnector(proxy="http://some.proxy.com")
r = await aiohttp.post('http://python.org', connector=conn, data=b"hello", headers={})
or
import aiohttp
from aiohttp import request
conn = aiohttp.ProxyConnector(proxy="http://some.proxy.com")
r = await request('post','http://python.org', connector=conn, data=b"hello", headers={})
来源:https://stackoverflow.com/questions/35132127/send-aiohttp-post-request-with-headers-through-proxy-connection