Skip to content

Instantly share code, notes, and snippets.

@fanbyprinciple
Last active January 15, 2025 06:42
Show Gist options
  • Save fanbyprinciple/4110dfc2c7f626659dc0cfcc9223d06e to your computer and use it in GitHub Desktop.
Save fanbyprinciple/4110dfc2c7f626659dc0cfcc9223d06e to your computer and use it in GitHub Desktop.
Python code for POST request
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