Postman 测试获取名为 "email" 的请求正文问题
Postman Test getting request body named "email" problem
我的邮递员请求正文中有这些属性
{
"firstName": "QA",
"lastName": "Test {{agent_phone_number}}",
"email": "qatest-{{agent_phone_number}}@mail.com"
}
我正在尝试在“测试”选项卡上获取请求正文并将它们设置在集合变量中,代码看起来像这样
const requestJson = JSON.parse(pm.request.body.raw);
pm.collectionVariables.set('agent_firstName', requestJson.firstName);
pm.collectionVariables.set('agent_lastName', requestJson.lastName);
pm.collectionVariables.set('agent_email'. requestJson.email);
当我 运行 它时,我得到了这个错误
TypeError: Cannot read property 'email' of undefined
当我检查集合变量时,名字和姓氏被保存,但电子邮件没有..
“email”是否类似于 Postman 上的“保留”关键字?如果是这样,那么我如何从我的请求正文中获取“电子邮件”属性?
你有一个。而不是 , 错别字:
pm.collectionVariables.set('agent_email'. requestJson.email);
应该是
pm.collectionVariables.set('agent_email', requestJson.email);
我的邮递员请求正文中有这些属性
{
"firstName": "QA",
"lastName": "Test {{agent_phone_number}}",
"email": "qatest-{{agent_phone_number}}@mail.com"
}
我正在尝试在“测试”选项卡上获取请求正文并将它们设置在集合变量中,代码看起来像这样
const requestJson = JSON.parse(pm.request.body.raw);
pm.collectionVariables.set('agent_firstName', requestJson.firstName);
pm.collectionVariables.set('agent_lastName', requestJson.lastName);
pm.collectionVariables.set('agent_email'. requestJson.email);
当我 运行 它时,我得到了这个错误
TypeError: Cannot read property 'email' of undefined
当我检查集合变量时,名字和姓氏被保存,但电子邮件没有..
“email”是否类似于 Postman 上的“保留”关键字?如果是这样,那么我如何从我的请求正文中获取“电子邮件”属性?
你有一个。而不是 , 错别字:
pm.collectionVariables.set('agent_email'. requestJson.email);
应该是
pm.collectionVariables.set('agent_email', requestJson.email);