python curl请求
时间: 2023-08-21 08:14:12 浏览: 183
回答: 在Python中,可以使用requests库来发送HTTP请求。下面是使用requests库发送curl请求的示例代码:
```python
import requests
headers = {
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Content-Length': '0',
'Origin': 'http',
'Pragma': 'no-cache',
'Referer': 'http',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
'accept': 'application/json'
}
# 发送POST请求
response = requests.post('http://httpbin.org/post', headers=headers, verify=False)
print(response.text)
# 发送GET请求
response = requests.get('http://httpbin.org/get', headers=headers, verify=False)
print(response.text)
# 发送PUT请求
response = requests.put('http://httpbin.org/put', headers=headers, verify=False)
print(response.text)
```
以上代码中,我们使用requests库发送了POST、GET和PUT请求,并打印了响应结果。你可以根据自己的需求修改请求的URL和headers参数。
#### 引用[.reference_title]
- *1* *2* *3* [【实现curl请求与python脚本的转化】](https://blog.csdn.net/hzxyzyq/article/details/127880140)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文