Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postman 如何通过POST请求调用下一个GET请求,POST请求使用;setNextRequest“;_Postman - Fatal编程技术网

Postman 如何通过POST请求调用下一个GET请求,POST请求使用;setNextRequest“;

Postman 如何通过POST请求调用下一个GET请求,POST请求使用;setNextRequest“;,postman,Postman,以下是场景: 给定我有多个输入数据(在请求前脚本中设置)用于请求后 当返回ID时 然后使用POST请求->测试中的“setNextRequest”命令断言通过GET请求传递ID的详细信息 注意:测试从collection runner运行 Request Body: { "name": "{{client_name}}", "email": "{{client_email}}" } Pre-request_script: pm.environment.set("client_n

以下是场景:

给定我有多个输入数据(在请求前脚本中设置)用于请求后 当返回ID时 然后使用POST请求->测试中的“setNextRequest”命令断言通过GET请求传递ID的详细信息

注意:测试从collection runner运行

Request Body:
{
    "name": "{{client_name}}",
    "email": "{{client_email}}"
}

Pre-request_script:
pm.environment.set("client_name","Client_" + new Date().getTime());
pm.environment.set("client_email", "Client_" + Math.random().toString(36).substr(2, 9) + "@abc.com");

Tests:
var jsonData = JSON.parse(responseBody);
if(jsonData.id){
    pm.environment.set("client-admin-client-id", jsonData.id);
    pm.sendRequest("GetClient By ID", function (err, response) {
    console.log(JSON.parse(response.json()));
}); 
}else{
    postman.setNextRequest(null);
}```
实际行为: 它无法访问ID为的GET URL

预期行为: 我需要从collection runner自动断言详细信息

Request Body:
{
    "name": "{{client_name}}",
    "email": "{{client_email}}"
}

Pre-request_script:
pm.environment.set("client_name","Client_" + new Date().getTime());
pm.environment.set("client_email", "Client_" + Math.random().toString(36).substr(2, 9) + "@abc.com");

Tests:
var jsonData = JSON.parse(responseBody);
if(jsonData.id){
    pm.environment.set("client-admin-client-id", jsonData.id);
    pm.sendRequest("GetClient By ID", function (err, response) {
    console.log(JSON.parse(response.json()));
}); 
}else{
    postman.setNextRequest(null);
}```

到目前为止你试过什么?什么不起作用?给我们看预请求代码?如果您使用的是
setNextRequest
,则此操作仅在集合运行程序中有效。更新了说明有人可以帮助我吗?您没有任何关于
pm的测试。除了
语句之外,您的断言是什么?什么是
if
语句条件检查,只是为了查看
id
属性是否存在?在
if
块中有一个
pm.sendRequest()
,这是干什么的?这与
setNextRequest()
不同。