request python body参数
时间: 2023-12-09 07:04:49 浏览: 166
根据提供的引用内容,可以使用以下方法来设置Python请求的body参数:
1. 使用`json`模块将参数转换为JSON格式,并在请求头中设置`Content-Type`为`application/json`,然后使用`requests.post`方法发送POST请求。
```python
import json
import requests
data = {
"cityCode": "130400",
"lineId": "711",
"direction": 0,
"list": [
{
"startTime": "2020-06-25 09:05:00",
"driver_name": "甲"
}
],
"start": "2020-06-25 08:00:00",
"end": "2020-06-25 11:00:00",
"targetDate": "2020-06-25"
}
headers = {
"Content-Type": "application/json"
}
response = requests.post("http://localhost:8087/manual/batchAdd", data=json.dumps(data), headers=headers)
```
上述代码将`data`参数通过`json.dumps`方法转换为JSON字符串,并在请求头中设置`Content-Type`为`application/json`,然后使用`requests.post`方法发送POST请求。
阅读全文
相关推荐
















