Skip to content

Instantly share code, notes, and snippets.

@popowa
Created April 1, 2016 00:47
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 popowa/ed4ec2bf4fdd492c719928297adce684 to your computer and use it in GitHub Desktop.
Save popowa/ed4ec2bf4fdd492c719928297adce684 to your computer and use it in GitHub Desktop.
import json
import urllib.request
request_data = {'name': 'User'}
request_url = 'https://my-api-id.execute-api.region-id.amazonaws.com/test/mydemoresource'
req = urllib.request.Request(request_url)
req.add_header('Content-Type', 'application/json; charset=utf-8')
jsondata = json.dumps(request_data)
jsondataasbytes = jsondata.encode('utf-8')
req.add_header('Content-Length', len(jsondataasbytes))
response = urllib.request.urlopen(req, jsondataasbytes)
print(response.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment