python的requests模块功能_[Python+requests]使用requests模块测试post接口,并将其与postman代码进行比较,Pythonrequests,对,Postman...

康爱多大药房的登录接口。

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dvc2hpeWlnZXJlbmxhaWRl,size_16,color_FFFFFF,t_70

请求方式:post

功能说明:登录

登录成功:{"Code":"1","Result":true,"Message":"登录成功!","Data":null}

登录失败:{Code: "UserName", Result: false, Message: "账户名不存在或密码不匹配,请重新输入!", Data: null}

参数名

说明

参数1

userNam

用户名,必填

参数2

pass

密码,必填

参数3

isRemberName

是否记住密码

参数4

loginPlatform

登录平台

使用requests正常编写代码

import requests

url = 'https://tstuser.360kad.com/Login/AjaxLoginV2'

data1 = {

'userName':'账号',

'pass':'密码',

'isRemberName':'false',

'loginPlatform':'1'

}

# 这2种写法都可以

# request = requests.request('post', url, data=data1)

request = requests.post(url, data1)

print(request.text)

if request.json()["Result"] == True: # 返回结果转成json格式

print("登录成功")

else:

print("登录失败,原因是:"+request.json()['Message'])

# postman导出requests格式的代码

import requests

url = "https://tstuser.360kad.com/Login/AjaxLoginV2"

payload = "userName=1232321&pass=12312312321312&isRemberName=false&loginPlatform=1&undefined="

headers = {

'cache-control': "no-cache",

'Postman-Token': "e828e60f-dab3-4c58-815d-fd8ae5652883"

}

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值