Created
August 12, 2013 20:49
-
-
Save kzim44/6215068 to your computer and use it in GitHub Desktop.
Post image to rest service with python and urllib2
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
import urllib2, os | |
image_path = "png\\01.png" | |
url = 'http://xx.oo.com/webserviceapi/postfile/' | |
length = os.path.getsize(image_path) | |
png_data = open(image_path, "rb") | |
request = urllib2.Request(url, data=png_data) | |
request.add_header('Cache-Control', 'no-cache') | |
request.add_header('Content-Length', '%d' % length) | |
request.add_header('Content-Type', 'image/png') | |
res = urllib2.urlopen(request).read().strip() | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment