pyrhon requests.post
时间: 2023-09-26 07:11:31 浏览: 100
post请求
requests.post is a method in the Python Requests library that sends a POST request to the specified URL with an optional payload and/or headers.
Syntax:
```
requests.post(url, data=None, json=None, **kwargs)
```
Parameters:
- url (string): URL to send the request to
- data (dict, tuple list, bytes, or file): (optional) Dictionary, tuple list, bytes, or file to send in the body of the request
- json (dict): (optional) A JSON serializable dictionary to send in the body of the request
- kwargs (optional): Additional arguments to pass to the method, such as headers or authentication information
Example:
```
import requests
payload = {'username': 'john', 'password': 'secret'}
headers = {'content-type': 'application/json'}
response = requests.post('https://example.com/login', json=payload, headers=headers)
print(response.status_code) # prints the response status code
print(response.json()) # prints the response content as JSON
```
阅读全文