介绍
这期内容当中小编将会给大家带来有关怎么在Python中使用指定的端口发送http请求,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
<强>使用请求库强>
class SourcePortAdapter (HTTPAdapter): ,““““Transport adapter", that allows us 用set 从而source 港口!”,“ ,def __init__(自我,,港口,* args,, * * kwargs): 时间=self.poolmanager 才能;没有 时间=self._source_port 才能;港口 超级才能(). __init__ (* args,, * * kwargs) ,def init_poolmanager(连接,自我,还以为,最大容量,块=DEFAULT_POOLBLOCK, * * pool_kwargs): 时间=self.poolmanager 才能;PoolManager ( ,,num_pools=连接,最大尺寸=最大容量, ,,块=块,source_address=(& # 39; & # 39;,, self._source_port)) 时间=s requests.Session () s.mount (& # 39; https://baidu.com& # 39;,, SourcePortAdapter (54321)) s.get (& # 39; https://baidu.com& # 39;)
我用wireshark测试发现是走的54321端口。
<强>使用pycurl库强>
c =, pycurl.Curl () c.setopt (c.URL, & # 39; https://curl.haxx.se/dev/& # 39;) c.setopt (c.LOCALPORT, 54321) c.setopt (c.LOCALPORTRANGE, [52314、56321、5532]) c.perform () c.close ()
测试好,可以直接在卷发命令行中测试。
curl ——local-port 12520, http://baidu.com
上述就是小编为大家分享的怎么在Python中使用指定的端口发送http请求了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。