标签: postman-pre-request-script

在postman pre-script中发送Post请求

我正在尝试使用邮递员在预脚本中发送 POST 请求,但收到错误“评估预请求脚本时出现错误:错误:意外标记 '<' at 1:1 ^”。不知道出了什么问题。谁能帮我这个?

pm.sendRequest({
url: 'http://localhost:8001/routes/d6b7a95a-fd91-4f8a-b8f6-10835f30170a',
method: 'PATCH',
headers: {"Content-Type": "application/json"},
body: { 
    mode: 'raw',
    raw:JSON.stringify({
        "protocols":["http","https"],
        "paths":["/target-paymentoriginal"],
        "methods":[]})}  }, 

function (err, response) {  console.log("Updated original route to target-payment"+response.json());  });
Run Code Online (Sandbox Code Playgroud)

postman postman-pre-request-script

4
推荐指数
1
解决办法
1万
查看次数

将 crypto hmac 转换为 crypto-js hmac 字符串

我正在尝试转换一个秘密的 hmac 字符串,以允许我在邮递员中测试我的 api。Postman 预装了 cryptojs。这是我在测试服务器上使用加密的过程:

const crypto = require('crypto');
const generateHmac = (privateKey, ts) => {
    const hmac = crypto.createHmac('sha256', privateKey);
    hmac.update(ts);
    const signature = hmac.digest('hex');
    return signature;
}
Run Code Online (Sandbox Code Playgroud)

这与 postman 中使用 cryptojs 生成的字符串不匹配:

const createHmacString = (privateKey, ts) => {
    const hmac = CryptoJS.HmacSHA256(ts, privateKey).toString(CryptoJS.enc.Hex)
    return hmac;
}
Run Code Online (Sandbox Code Playgroud)

不知道我在这里做错了什么。提前致谢!

javascript encryption hmac node.js postman-pre-request-script

3
推荐指数
1
解决办法
2909
查看次数

如何在 Postman 预查询脚本和正文中获取当前的 ISO8601 时间戳?

在预查询脚本中使用 Postman 和以下代码

   const moment = require('moment');
   pm.globals.set("timestamp", moment().format("YYYY-MM-DDTHH:MM:SSZ"));
Run Code Online (Sandbox Code Playgroud)

我得到作为回应

请求签名过去太远,已过期。时间戳日期:2019-11-30T10:11:10+00:00

在正文中,我使用的是 {{timestamp}}。

我需要 ISO8601 格式的时间戳。

如果我使用

    {{$timestamp}}
Run Code Online (Sandbox Code Playgroud)

它返回一个 Linux 日期 1575110444,它在今天 10:41 是正确的

iso8601 postman postman-pre-request-script

3
推荐指数
2
解决办法
4746
查看次数

具有预请求脚本的邮递员:“错误:解析错误:标头溢出”

仅当使用一些预请求脚本运行本地应用程序的请求时,我才遇到此问题:

Error: Parse Error: Header overflow

Postman 版本是:v7.25.0。

PS:对于我的服务器应用程序的相同请求,我没有收到任何错误。

postman postman-pre-request-script

2
推荐指数
1
解决办法
7358
查看次数

在postman v8中的预请求脚本中访问cookie

我正在尝试获取预请求脚本中的 cookie,以将其与其他请求链接起来,该请求使用下面的示例作为空数组返回。

在最新版本的 postman v8 中,无法使用 pm.sendRequest 获取 cookies 对象,否则该对象可以在低于 8 的 postman 版本中工作。

pm.sendRequest(url, function (err, response, { cookies }) {
    console.log(cookies.all());
});
Run Code Online (Sandbox Code Playgroud)

postman postman-pre-request-script

2
推荐指数
1
解决办法
1668
查看次数

如何在 Postman JSON 正文中添加注释(用于集合级别预请求脚本)

我想在 JSON 正文中使用注释来进行快速引用,如下所示:

{
    /**
    * some param info
    *   param: [
    *     1 = value so
    *     2 = value that
    *   ]
    */
    "param": [
        1
    ],
    /* some param2 info */
    "param2": "value",
    // pls use this
    "param3": [
        "values"
        //"home"
    ]
}
Run Code Online (Sandbox Code Playgroud)

在请求发送到服务器之前应该过滤掉评论。

postman postman-pre-request-script

2
推荐指数
1
解决办法
2032
查看次数

如何在 Postman 的预请求脚本中使用 Faker 变量?

PostMan 支持 faker-library 并提供了几个变量,如“randomFirstName”等。但是,我尝试让它们在预请求脚本中工作。

我发现了一篇关于这个主题的博文,告诉我它实际上应该有效:

pm.variables.replaceIn("{{$randomProductName}}")
Run Code Online (Sandbox Code Playgroud)

然而,对我来说这不起作用。该变量不会被替换:

var firstName = "{{$randomFirstName}}"

console.log(firstName)
Run Code Online (Sandbox Code Playgroud)

输出是:

{{$randomFirstName}}

如何在 PostMan 的预请求脚本中使用这些变量?

postman postman-pre-request-script

0
推荐指数
1
解决办法
2904
查看次数