问题描述
我必须在我的请求中设置一个参数,该参数是另外两个参数的md5散列。我认为预先请求脚本可以完成这项工作,但我不知道如何在此脚本中计算md5。任何想法?
您可以创建以下预先请求脚本,前提是您的参数是定义的环境变量。你需要调整这个例子,如果它们以其他方式定义的话。
//访问你的env变量像这样
var str_1 = environment.variable_1 + environment.variable_2;
//或者获取您的请求参数
var str_2 = request.data [foo] + request.data [bar];
//使用CryptoJS
var hash = CryptoJS.MD5(str_1 + str_2).toString();
//设置新的环境变量
postman.setEnvironmentVariable('hash',hash);
CryptoJS的工作原理是它在Postman中可用(以及lodash,backbone等)。
访问环境变量很容易通过环境
对象。
设置环境变量可以通过 postman
对象获得。
在这个预先请求运行之后,您可以访问 hash
使用正常的 {{hash}}
简写变量。
另外,您可以阅读了解Postman中提供的库,变量和属性。
I have to set a parameter in my request that is a md5 hash of two other parameters. I think a pre-request script can do the job, but I do not know how to compute a md5 in this script. Any idea?
You can create the following pre-request script provided your parameters are defined environment variables. You would need to tweak this example if they are defined in some other fashion.
// Access your env variables like this
var str_1 = environment.variable_1 + environment.variable_2;
// Or get your request parameters
var str_2 = request.data["foo"] + request.data["bar"];
// Use the CryptoJS
var hash = CryptoJS.MD5(str_1 + str_2).toString();
// Set the new environment variable
postman.setEnvironmentVariable('hash', hash);
CryptoJS works because it's available in Postman (as well as lodash, backbone etc).
Accessing environment variables is easy through the environment
object.
Setting environment variables is available through the postman
object.
After this pre-request has run you can access the hash
variable using the normal {{hash}}
shorthand.
Also, you can read here about libraries, variables and properties available in Postman.
这篇关于如何在PostMan中的预先请求脚本中计算md5散列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!