# test_client.pyfrom poster.enpre import multipart_enprefrom poster.streaminghttp import register_openersimport urllib2# Register the streaming http handlers with urllib2register_openers()# Start the multipart/form-data encoding of the file "DSC0001.jpg"# "image1" is the name of the parameter, which is normally set# via the "name" parameter of the HTML <input> tag.# headers contains the necessary Content-Type and Content-Length# datagen is a generator object that yields the enpred parametersdatagen, headers = multipart_enpre({"image1": open("DSC0001.jpg")})# Create the Request objectrequest = urllib2.Request("http://localhost:5000/upload_image", datagen, headers)# Actually do the request, and get the responseprint urllib2.urlopen(request).read()
这工作得很完美,我也不必为httplib烦恼。该模块位于此处:http
:
//atlee.ca/software/poster/index.html
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)