Skip to content

Instantly share code, notes, and snippets.

@pcote
Created August 6, 2012 19:43
Show Gist options
  • Save pcote/3277886 to your computer and use it in GitHub Desktop.
Save pcote/3277886 to your computer and use it in GitHub Desktop.
Python 3 example script for sending data to a web application using the post method.
"""
post_test.py
An example script that shows how to send data by post-method from
command-line to a web application.
"""
import urllib.request as request
import urllib.response as response
import urllib.parse as parse
url_string = "http://localhost:8085/A_WebApp/targetservlet"
data_dict = {'testFormVar': 'foobar'}
data = parse.urlencode(data_dict)
binary_data = data.encode('utf-8')
req = request.Request(url_string, binary_data)
sock = request.urlopen(req)
raw_result = sock.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment