几行代码实现Python测试post接口

一直以来都用PostMan来测试接口,偶尔试了下Python,觉得很好用,也很方便。废话不说上代码。

import requests 
header={
  "Content-Type":"application/json"
}
datas={
  "code":"vlFa/yJf+eQOiILvrVa8pnI/WPK2EFaSofwcgoS2fGI="
}
url="http://112.31.150.64:9898/jdServicePurchase/gettoken"
r = requests.post(url, json=datas,headers=header)
print("状态码:"+ str( r.status_code ) ) #打印状态码
print(r.text)

首先,运行上面代码需要安装requests模块,如果已经安装可以直接运行上面代码。

pip install requests

如果网速不好,也可以用国内源:pypi镜像(清华源)

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests

其次,将datas和url改成自己的参数和地址。

好了可以直接运行了。

posted @ 2022-04-11 10:58  =云在青天水在瓶=  阅读(327)  评论(0)    收藏  举报