Skip to content

Instantly share code, notes, and snippets.

@cgwxyz
Last active August 29, 2015 14:02
Show Gist options
  • Save cgwxyz/dcd31280d380aef4a105 to your computer and use it in GitHub Desktop.
Save cgwxyz/dcd31280d380aef4a105 to your computer and use it in GitHub Desktop.
Python urllib2 post sample
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