【问题标题】:Postman giving 400 for pm.sendRequest邮递员为 pm.sendRequest 提供 400
【发布时间】:2021-10-08 09:38:30
【问题描述】:

当我在 Postman - Tests 发送请求下方运行时,收到 400 个错误请求。 谁能告诉我发送请求的错误在哪里?

let loginRequest = {
        url: new_url,
        method: 'POST',
        headers: {
            "Content-Type": "application/json",
            "Authorization":autho
        },
        body: { 
            mode: 'raw',
            raw:JSON.stringify({
                "name":child_group,
                "description":"Create Via RestAPI"
            })}  
    };
    // send request 
        pm.sendRequest(loginRequest, function (err, res) {
            console.log(err ? err : res.text());
        });

错误: { "message" : "缺少授权标头。"}

【问题讨论】:

  • 应该是header 而不是headers

标签: postman postman-collection-runner postman-pre-request-script postman-testcase


【解决方案1】:

@Manish Katepallewar,这对我有用:

let loginRequest=
{
 url:new_url,
 method:'post',
 header:
 {
  'Content-Type':'application/json',
  'Authorization':autho
 },
 body:
 { 
  mode:'raw',
  raw:JSON.stringify(
  {
   'name':child_group,
   'description':'Create Via RestAPI'
  })
 }  
};

pm.sendRequest(loginRequest,function(err,res)
{
 console.log(err?err:res.text());
});

【讨论】:

    猜你喜欢
    • 2022-01-21
    • 2018-05-29
    • 1970-01-01
    • 2018-07-22
    • 2020-09-27
    • 1970-01-01
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多