You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Postman调用pm.sendRequest返回400提示缺少Authorization头如何解决

核心问题原因

你写的pm.sendRequest请求配置里,请求头的配置键名错误:pm.sendRequest规范中请求头对应的配置字段是单数header,不是你代码里写的复数headers,这个字段不被Postman识别,所以你配置的Authorization头根本没有被携带到请求中,服务端自然返回缺少Authorization头的报错。

修复步骤
  1. 把请求配置里的headers改成header即可,修正后的代码如下:
// 注意提前确保autho、new_url、child_group三个变量已经正确赋值
let loginRequest = {
        url: new_url,
        method: 'POST',
        // 这里把headers改成header
        header: {
            "Content-Type": "application/json",
            "Authorization":autho
        },
        body: { 
            mode: 'raw',
            raw:JSON.stringify({
                "name":child_group,
                "description":"Create Via RestAPI"
            })}
    };
// 可选:加日志确认请求配置是否正确
console.log("请求配置:", loginRequest)
pm.sendRequest(loginRequest, function (err, res) {
    console.log(err ? err : res.text());
});
  1. 额外校验:如果修改后还是报错,按下面步骤排查
  • 打印autho变量的值,确认该变量不是undefined、null,也没有拼写错误,比如Bearer类型的token要确保带Bearer 前缀,示例:const autho = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  • 确认new_url地址正确,没有出现跳转导致请求头丢失的情况

内容的提问来源于stack exchange,提问作者Manish Katepallewar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.09 11:48:03