用requests.post请求页面,获取不到

加完参数之后,还是什么都没有图片说明

来源https://www.jianshu.com/p/4597db4d8415

# -*- coding:utf-8 -*-
import json
import urllib.request
# 测试的url
url=https://www.testurl.com
# 请求头
header = {"Content-Type": "application/json"}
# 入参
value ={"name":"zhangsan","grade":"大一"}
# 把入参进行json格式的编码
data = json.dumps(value)
# data出来的是字符串格式,需要转换成字节格式,传参只能接受字节格式
datas = bytes(data, 'utf-8')
# 请求接口
response = urllib.request.Request(url, datas, header)
# 将已编码的 JSON 字符串解码为 Python 对象
html = json.loads(urllib.request.urlopen(response).read().decode('utf-8'))
print(html)