Skip to content

Instantly share code, notes, and snippets.

@chand1012
Created October 11, 2021 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chand1012/c5315071600002993bc3877ee27fbd34 to your computer and use it in GitHub Desktop.
Save chand1012/c5315071600002993bc3877ee27fbd34 to your computer and use it in GitHub Desktop.
POSTs a JSON file as a request body to the specified URL
import requests
import json
import sys
# first argument is the url
# second argument is the file name
url = sys.argv[1]
file_name = sys.argv[2]
# load json file with test data
with open(file_name) as json_file:
data = json.load(json_file)
# post the gotten json data to the server
r = requests.post(url, json=data)
# print the response text to console
print(r.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment