Skip to content

Instantly share code, notes, and snippets.

@cocoajin
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocoajin/2d8693d73508c425f597 to your computer and use it in GitHub Desktop.
Save cocoajin/2d8693d73508c425f597 to your computer and use it in GitHub Desktop.
httplib https post 请求
#coding=utf-8
'''
Created on 2014年9月17日
@author: cocoajin
test
'''
import httplib, urllib
host='httpbin.org'
url = '/login'
url='/post'
values = {
'account':'123',
'password':'abc',
'cookie':'1'
}
headers = {
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.122 Safari/537.36',
'Content-Type':'application/x-www-form-urlencoded'
}
values = urllib.urlencode(values)
conn = httplib.HTTPSConnection(host)
conn.request("POST", url, values, headers)
response = conn.getresponse()
data = response.read()
print 'Response: ', response.status, response.reason
print data
Response: 200 OK
Data:
{
"args": {},
"data": "",
"files": {},
"form": {
"account": "123",
"cookie": "1",
"password": "abc",
},
"headers": {
"Accept-Encoding": "identity",
"Connection": "close",
"Content-Length": "68",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.122 Safari/537.36",
"X-Request-Id": "fec15189-9e04-4e40-8659-257d1fb812ec"
},
"json": null,
"origin": "58.56.5.3",
"url": "https://httpbin.org/post"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment