Created
October 28, 2014 01:53
-
-
Save taojy123/4ed4c9c61b2af1465f18 to your computer and use it in GitHub Desktop.
Python 模拟POST发包上传文件
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
# requests | |
import requests | |
r = requests.post("http://127.0.0.1:8000/input_file/", files={"file": open("a.txt", "rb")}) | |
print r.url | |
print r.text | |
# poster | |
from poster.encode import multipart_encode | |
from poster.streaminghttp import register_openers | |
import urllib2 | |
register_openers() | |
datagen, headers = multipart_encode({"file": open("a.txt", "rb")}) | |
request = urllib2.Request("http://127.0.0.1:8000/input_file/", datagen, headers) | |
s = urllib2.urlopen(request).read() | |
print s | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment