curl有一个选项connect-to
--connect-to <HOST1:PORT1:HOST2:PORT2>
For a request to the given HOST:PORT pair, connect to CONNECT-TO-HOST:CONNECT-TO-PORT instead. This option is suitable to direct requests at a specific
server, e.g. at a specific cluster node in a cluster of servers. This option is only used to establish the network connection. It does NOT affect the host-
name/port that is used for TLS/SSL (e.g. SNI, certificate verification) or for the application protocols. "host" and "port" may be the empty string, meaning
"any host/port". "connect-to-host" and "connect-to-port" may also be the empty string, meaning "use the request's original host/port".
This option can be used many times to add many connect rules.
Python Requests库中的等价物是什么?
1条答案
按热度按时间aiazj4mn1#
没有这样的等价物,但您可以在创建连接之前修补较低级别以重写远程地址。
这在Python 3中是可行的:
像修补PoolManager或使用自定义适配器这样的解决方案是不够的,因为URL也会被重写(因此
Host:
头也会被重写)。当你使用curl --connect-to
时,在HTTP级别没有任何改变。我还需要选择性地强制http连接,尽管有URL方案。这是它的工作增强版本:
参见Python 'requests' library - define specific DNS?。