python requests
时间: 2023-09-12 12:03:56 浏览: 120
win与linux系统中python requests 安装
Python requests是一个HTTP库,它允许Python发送HTTP/1.1请求,包括GET、POST、PUT、DELETE、HEAD、OPTIONS等方法,并支持cookie、header、SSL等特性。
使用requests发送GET请求的示例代码如下:
```
import requests
response = requests.get('http://httpbin.org/get')
print(response.status_code)
print(response.text)
```
这段代码使用requests库发送一个GET请求到'http://httpbin.org/get',并打印出返回的状态码和响应内容。
同样地,使用requests发送POST请求的示例代码如下:
```
import requests
url = 'http://httpbin.org/post'
data = {'name': 'Tom', 'age': 20}
response = requests.post(url, data=data)
print(response.status_code)
print(response.text)
```
这段代码使用requests库发送一个POST请求到'http://httpbin.org/post',并将data作为请求的参数,然后打印出返回的状态码和响应内容。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [python requests详解](https://blog.csdn.net/godnightshao/article/details/129764556)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文