Created
November 29, 2010 15:05
-
-
Save lerouxb/720047 to your computer and use it in GitHub Desktop.
Do a POST request on a URL, print status, headers and response body.
This file contains hidden or 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
| #!/usr/bin/env python | |
| import httplib | |
| import sys | |
| from urlparse import urlparse | |
| def post(url, params): | |
| r = urlparse(url) | |
| conn = httplib.HTTPConnection(r.netloc) | |
| pathquery = r.path | |
| if r.query: | |
| pathquery = pathquery + '?' + r.query | |
| conn.request("POST", pathquery, params) | |
| res = conn.getresponse() | |
| print res.status, res.reason | |
| for k, v in res.getheaders(): | |
| print k+': '+v | |
| print res.read() | |
| conn.close() | |
| if __name__ == "__main__": | |
| if len(sys.argv) >= 2: | |
| url = sys.argv[1] | |
| params = '' | |
| if len(sys.argv) > 2: | |
| params = sys.argv[2] | |
| post(url, params) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment