Last active
January 15, 2025 06:42
-
-
Save fanbyprinciple/4110dfc2c7f626659dc0cfcc9223d06e to your computer and use it in GitHub Desktop.
Python code for POST request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| data = "hi" | |
| response = requests.post("https://httpbin.org/post", | |
| data=json.dumps(data) | |
| headers={"Content-import requests | |
| import json | |
| data = { | |
| "content": "something something" | |
| } | |
| response = requests.post( | |
| "https://request.com/post", | |
| data=json.dumps(data), | |
| headers={'Content-Type': 'application/json'} | |
| ) | |
| # Check the status code and print the response content | |
| print("Status Code:", response.status_code) | |
| print("Response Text:", response.text) | |
| # If successful, try to parse JSON | |
| if response.status_code == 200: | |
| print(response.json()) | |
| else: | |
| print("Error: Unable to retrieve valid JSON response.")Type": "application/json"}, | |
| ) | |
| print(response.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment