• 发送json格式post请求


    接口测试中遇到post请求参数要以json格式发送
    查阅了一些资料用了requests.request方法 参数直接json=来发送
    添加headers  = {'Content-Type': 'application/json;charset=UTF-8'} 规定参数内容格式是application/json格式

    重写一下请求函数

    import requests
    def myrequest(method,url,json,headers):
    if method == "get":
    res = requests.request(url,method,json=json,headers=headers)
    elif method == "post":
    res = requests.request(method,url,json=json,headers=headers)
    else:
    res = None
    return res.text,res.status_code


    url="http://trade.xxxx.com.cn/open/api/mtzc/xxxxxxxxxx"
    method="post"
    json={"bizFlow": "sddfsssesseee",
    "assetsCode": "2e92dc6c75ab4314a8ff30bd12"}
    headers = {'Content-Type': 'application/json;charset=UTF-8'}
    res=myrequest(method,url,json,headers)
    print(res)
  • 相关阅读:
    《炒股的智慧》
    python函数初识
    python文件操作
    python 表 字典 数据补充
    python深浅copy,is,id
    python列表字典小练习
    python列表字典练习
    python for/range练习
    python列表练习
    python每日小练习
  • 原文地址:https://www.cnblogs.com/nuonuozhou/p/10510580.html
Copyright © 2020-2023  润新知