#!/usr/bin/env python
#-*- coding: utf-8 -*-
import httplib, urllib
import json
httpClient = None
try:
params = {'user':'ero','password':'em3'} #python object
print params[1]
#x =json.JSONEncoder()
#params_str = x.encode(params) #python obj to json(str)
params_str = json.dumps(params) #python obj to json(str)
print params_str
headers = {'content-type': 'application/json;charset=UTF-8', 'Accept':'text/plain'}
httpClient = httplib.HTTPConnection("172.28.125.159",21112, timeout=5)
httpClient.request("POST", "/esmpro/api/login-session", params_str, headers)
response = httpClient.getresponse()
print response.status
print response.reason
print response.read()
print response.getheaders()#取得返回值
y = response.getheaders() #python object
print y[2]
i= json.dumps(response.getheaders())
print i
n = json.loads(i)
print n[0][0]
except Exception, e:
print e
finally:
if httpClient:
httpClient.close()
网友评论