Created
August 6, 2012 19:43
-
-
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.
This file contains 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
""" | |
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