locust -post请求

Posted yanhuidj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了locust -post请求相关的知识,希望对你有一定的参考价值。

------------恢复内容开始------------

参考:https://www.cnblogs.com/imyalost/p/9758189.html

#coding=utf-8
import requests
from locust import HttpLocust,TaskSet,task
class Msg(TaskSet):

@task(1)
def get_blog(self):

header = { "Content-Type":"application/json"}
payload={
"data": "{"phone":"7029876553",:"message‘s body","action":"https://www.baidu.com"}",
"appId": 1,
"sign": "d9347eb257a0",
"id": "500",
"packageName": "team.xxx.pay",
"body": "message‘s body",
"businessType": "pay",
"list": ["7029876123213553","702912312876554","7020981231236549"],
"title": "test11:06--message‘s title",
"operator": "1"
}



req = self.client.post("/push/push",data=payload ,headers=header, verify=False)
if req.status_code == 200:
print("success")
else:
print("fails")


class websitUser(HttpLocust):
task_set = Msg
min_wait = 1000 # 单位为毫秒
max_wait = 3000 # 单位为毫秒


if __name__ == "__main__":
import os

os.system("locust -f locust_api.py --host=http://dev.xxx.com")

------------恢复内容结束------------

以上是关于locust -post请求的主要内容,如果未能解决你的问题,请参考以下文章

Locust 参数说明

httprunner学习16-locust性能测试

Locust 参数说明

python+locust性能测试之No Web UI模式下运行Locust

Locust 介绍

Locust 分布式运行