python接口测试http协议的get方法,参数为json

# encoding = utf-8
__author__ = 'appqa4'

import urllib3
from urllib.parse import urlencode
import json
# from urllib3 import ProxyManager
url = 'http://splash.grayaegis.com/test/trans/json'

data = {"name": "LL", "age": 23}
# 把字典转化成json串儿
# json_foo1 = json.dumps(jsonParam) #字典格式转化为json格式
json_foo1 = json.dumps(data)
# json_foo2 = json.loads(json_foo1) # json数据转化为字典
headers = {'Content-Type': 'application/json'
}
# 把json串儿赋值给参数(名),字典形式(key-value)
t = {"jsonParam": json_foo1}
print(json_foo1,t)
#print(jsonParam["name"])
http = urllib3.PoolManager()
# 按照GET方法URL特点拼接url,字典k-v参数解析成url可接受的形式(urlencode)
r = http.request('GET',url+'?'+urlencode(t))
# 对返回数据进行utf-8解码
json_foo3 = r.data.decode('utf-8')
print(json_foo3)
python
原文地址:https://www.cnblogs.com/learnzone-fumu/p/11375359.html