Last active
August 29, 2015 14:02
-
-
Save cgwxyz/dcd31280d380aef4a105 to your computer and use it in GitHub Desktop.
Python urllib2 post sample
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
config = { | |
'api_host':'github.com', | |
'api_script':'test.php' | |
} | |
params = { | |
'code':1, | |
'file_id':123454, | |
'file_name':"v/test.mp4", | |
'file_size':3653.32 | |
} | |
params = urllib.urlencode(params) | |
logger.info("get param:"+params) | |
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/html"} | |
conn = httplib.HTTPConnection(config['api_host']) | |
conn.request("POST",config['api_script'], params, headers) | |
response = conn.getresponse() | |
logger.info("send data to api,get http code:"+str(response.status)) | |
if response.status == 200 : | |
data = response.read() | |
logger.info("get return:"+data) | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment