javascript 评估预请求脚本时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48429643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
There was an error in evaluating the Pre-request Script
提问by cyber8200
I'm trying to access the response of my POST request in Postman via Post Request Script.
我正在尝试通过 Post Request Script 在 Postman 中访问我的 POST 请求的响应。
I added this 2 lines, under Pre-request Script
我在下面添加了这 2 行 Pre-request Script
let response = pm.response.json();
console.log('JSON Response: ',response );
Then, I opened up my Postman console, before hit Sendto make my POST request
然后,我打开了我的 Postman 控制台,然后点击Send发出我的 POST 请求
I kept getting
我一直得到
There was an error in evaluating the Pre-request Script: TypeError: Cannot read property 'json' of undefined
评估预请求脚本时出错:TypeError:无法读取未定义的属性“json”
Do I need to enable anything on Postman?
我需要在 Postman 上启用任何东西吗?
回答by Clint
Pre-request scripts are ran before the request is sent. You do not have a response yet.
在发送请求之前运行预请求脚本。您还没有回复。
Try putting your script under the Teststab, which is ran after a response is received.
尝试将您的脚本放在Tests选项卡下,该选项卡在收到响应后运行。


