python3.6 HTTP POST JSON方式调用API接口

import urllib.parse


import requests




def http_test(): 
    url = 'http://192.168.6.200/sapcon/sapapi/in/100000'
#     f    = open("aa.txt", encoding='utf-8')
#     body = json.load(f) 
    body = [
                {
                    "pt":"B",
                    "pv":[
                        {
                            "PZ_NO1":"5000000000"
                        }
                    ]
                }
            ]


    req = requests.post(url,json=body)#发送post请求,第一个参数是URL,第二个参数是请求数据
    print(req.json())
    print(type(req.json()))
    print(req.json().get('retResult'))
    x = req.json().get('lsResult')[0].get('pv')[0].get('LIFNRN')
    print(urllib.parse.unquote(x))


if __name__=='__main__':
    http_test()

你可能感兴趣的:(Python)