python 如何使用charles的证书实现post访问
要在Python中使用Charles的证书实现POST访问,需要执行以下步骤:
-
打开Charles,导出证书:在Charles中,选择“Help”菜单,然后选择“SSL Proxying”>“Install Charles Root Certificate”。在弹出的对话框中选择“Save File”,将证书保存到本地。
-
将证书添加到Python的证书存储中:在Python的代码中,使用以下代码将证书添加到证书存储中。
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
- 使用证书进行POST请求:在Python的代码中,使用以下代码进行POST请求,其中包括使用证书的代码。
import requests
# 设置代理
proxy = {'http': 'http://127.0.0.1:8888', 'https': 'http://127.0.0.1:8888'}
# 设置证书路径
cert = '/path/to/charles/certificate.pem'
# 发送POST请求
r = requests.post(url, data=data, proxies=proxy, verify=cert)
其中,/path/to/charles/certificate.pem是导出的证书的路径,url和data分别是请求的URL和POST的数据。proxies参数指定代理地址,verify参数指定证书路径。
这样就可以使用Charles的证书实现POST访问了
原文地址: https://www.cveoy.top/t/topic/hm56 著作权归作者所有。请勿转载和采集!