我是这样做的:
# prepare the headers to send to the remote host
headers = {"key":"value",
"key":"value"}
# prepare the data for the POST body
data = {"key":"value",
"key":"value"}```
with connection_object.client.post(url, headers=headers,
json=data, name=task_name, catch_response=True) as response:
# convert the response to JSON
msg = json.loads(response.content.decode('utf-8'))
if response.status_code == 200:
# we got a 200 OK
response.success()
else:
response.failure("failure text")
在此示例中,此代码在从 UserBehavior 类调用的单独函数中运行,因此如果您在该类的任务中执行此操作,则 connection_object 为“self”。
在你的例子中,改变
r = requests.post(url = 'https://ABCD123.XYZ.QWERTY:9010/public/api/v1/ABC_TEST/query',
json = {"par1" : par1, "par2" : par2, "par3" : par3}, verify = verify, proxies = proxies)
到
class UserBehavior(SequentialTaskSet):
@task()
def task1(self):
r = self.client.post('https://ABCD123.XYZ.QWERTY:9010/public/api/v1/ABC_TEST/query',
json = {"par1" : par1, "par2" : par2, "par3" : par3},
verify = verify, proxies = proxies)
我相信你已经看过this,它显示的是“get”,而不是“post”。如果您不熟悉 requests 库,可能会让人感到困惑。
希望对您有所帮助!