admin管理员组文章数量:1356940
Using below snippet:
var timestamp = $.now().toString();
postman.setEnvironmentVariable("timestamp", timestamp);
postman.setEnvironmentVariable("apikey", obfuscateApiKey('yourapikey', timestamp));
Getting error: There was an error in evaluating the Pre-request Script: ReferenceError: $ is not defined
Not good in JavaScript, need to check.
Using below snippet:
var timestamp = $.now().toString();
postman.setEnvironmentVariable("timestamp", timestamp);
postman.setEnvironmentVariable("apikey", obfuscateApiKey('yourapikey', timestamp));
Getting error: There was an error in evaluating the Pre-request Script: ReferenceError: $ is not defined
Not good in JavaScript, need to check.
Share Improve this question edited Dec 15, 2017 at 15:55 Stefan 2,0682 gold badges36 silver badges55 bronze badges asked Dec 15, 2017 at 15:15 Niati AroraNiati Arora 1292 gold badges3 silver badges8 bronze badges 2- Sounds like you need to include jquery. Also, not sure this has anything to do with java... – user184994 Commented Dec 15, 2017 at 15:17
-
Do you mean Postman, the API testing app? What do you do exactly? Seems to me that you're just missing a lib like jQuery that defines the
$
– Stefan Commented Dec 15, 2017 at 15:18
3 Answers
Reset to default 3try
var timestamp = (new Date).getTime().toString(); instead of var timestamp = $.now().toString();
Postman doesn't use jQuery, but you can use a cutdown version of it called CheerioJS, see the documentation here.
It doesn't support now() but from the jQuery documentation for now():
The $.now() method is a shorthand for the number returned by the expression (new Date).getTime()
So you can just use the standard javascript here.
See this postman blog post for more info on using CheerioJS within postman.
You could achieve this without the need to use CheerioJS in Postman.
You could use the built-in {{$timestamp}}
global variable that gets created at runtime but that only seems to work in URL, Headers etc.
So you could just do this, for example:
var timestamp = (new Date).getTime().toString()
postman.setEnvironmentVariable("apikey", obfuscateApiKey('yourapikey',
timestamp))
本文标签: javascriptPostman giving error for prerequest scriptStack Overflow
版权声明:本文标题:javascript - Postman giving error for pre-request script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744064026a2584655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论