send aiohttp post request with headers through proxy connection

纵然是瞬间 提交于 2019-12-23 16:04:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!