Python2.X代码转换成Python3.X代码

importhttp.libimportjsonconn=httplib.HTTPConnection("localhost:8080")headers={"Conten... import http.lib
import json
conn = httplib.HTTPConnection("localhost:8080")
headers = {"Content-type":"application/json"} #application/x-www-form-urlencoded
params = ({"bindHyCardInfo":{"mobileNo":"1881026xxxx","userId":"2","cardno":"7926279367963021","cardpasswd":"xxxxxxxxxxxxxxx","ip":"127.0.0.1"},"header":{"version":"1.0.1","from":"1000","to":"2000","tid":"7926279367963021","time":"12312","token":"SEW342WEER2342","ext":""}})
conn.request("POST", "/core-oper/rest/bindCard", json.JSONEncoder().encode(params), headers)
response = conn.getresponse()
data = response.read()
if response.status == 200:
print ('success')
print (data)
else:
print ('fail')
conn.close()
展开
 我来答
就烦条0o
2016-07-12 · 知道合伙人软件行家
就烦条0o
知道合伙人软件行家
采纳数:33315 获赞数:46494
从事多年系统运维,喜欢编写各种小程序和脚本。

向TA提问 私信TA
展开全部
import http.client
import json
conn = http.client.HTTPConnection("localhost:8080")
headers = {"Content-type":"application/json"} #application/x-www-form-urlencoded
params = ({"bindHyCardInfo":{"mobileNo":"1881026xxxx","userId":"2","cardno":"7926279367963021","cardpasswd":"xxxxxxxxxxxxxxx","ip":"127.0.0.1"},"header":{"version":"1.0.1","from":"1000","to":"2000","tid":"7926279367963021","time":"12312","token":"SEW342WEER2342","ext":""}})
conn.request("POST", "/core-oper/rest/bindCard", json.JSONEncoder().encode(params), headers)
response = conn.getresponse()
data = response.read()
if response.status == 200:
    print('success')
    print(data)
else:
    print('fail')
    conn.close()

你看看这行不行

追问
太感谢了,还能再麻烦您一下么?
我的http head是这样的
请求HTTP HEAD:
Authorization:Basic base64.encoding(appKey:appSecret)
Accept :application/json
Content-Type:application/json;charset=UTF-8
如何按照我的head对原代码进行修改呢?
追答
改这里
params = ({"bindHyCardInfo":{"mobileNo":"1881026xxxx","userId":"2","cardno":"7926279367963021","cardpasswd":"xxxxxxxxxxxxxxx","ip":"127.0.0.1"},"header":{"version":"1.0.1","from":"1000","to":"2000","tid":"7926279367963021","time":"12312","token":"SEW342WEER2342","ext":"", "Authorization":"Basic base64.encoding(appKey:appSecret)","Accept":"application/json","Content-Type":"application/json;charset=UTF-8"}})
你看看行不行吧
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式