An Interest In:
Web News this Week
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
- April 18, 2024
August 23, 2021 10:41 am GMT
Original Link: https://dev.to/ayabouchiha/sending-a-post-request-in-python-3mgh
Sending A POST Request In Python
What's POST request
POST: is a request that is used for sending information or data to a specific server.
installation
pip install requests
Sending POST requests in Python
import requestsimport jsonurl = 'https://jsonplaceholder.typicode.com/posts'data = { 'title': 'buy new mouse','body': 'I need to buy a new mouse !','userId': 5,}headers = {'content-type': 'application/json; charset=UTF-8'}response = requests.post(url, data=json.dumps(data), headers=headers)# 201print(response.status_code)# Trueprint(response.ok)# b'{
"title": "buy new mouse",
"body": "I need to buy a new mouse !",
"userId": 5,
"id": 101
}'print(response.content)# {# "title": "buy new mouse",# "body": "I need to buy a new mouse !",# "userId": 5,# "id": 101# }print(response.text)# <class 'str'>print(type(response.text))# https://jsonplaceholder.typicode.com/postsprint(response.url)# application/json; charset=utf-8print(response.headers['Content-Type'])# utf-8print(response.encoding)
tutorials to learn requests
- Python Requests Tutorial: Request Web Pages, Download Images, POST Data, Read JSON, and More
- Requests in Python | Python Request Tutorial | Python Tutorial For Beginners | Edureka
- Python Requests Tutorial
- python-requests
Suggested posts
Happy coding!
Original Link: https://dev.to/ayabouchiha/sending-a-post-request-in-python-3mgh
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To