我们在生产中面临一个问题,即“Content-Length” header 没有被发送,即使我们在 header 属性中对其进行硬编码,所以我们从服务器收到 411 Length Required 错误。
我们正在使用:
- Axios 0.16.2
- NodeJS 6.10
- 部署在 AWS Lambda 环境中的应用
导致问题的代码如下:
let cookieJar;
const postBody = "MyBody=MyBodyContentGoesHere";
const url = "https://my-url.com";
return axios
.post(url,
postBody,
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
timeout: 10000,
jar: cookieJar,
withCredentials: true
}
);
我在 .NET 中编写了一个应用程序, header 已正确发送(无需手动传递)。这个 .NET 应用程序只是为了测试而编写的,它不是真正的应用程序。
你有什么想法吗? 我在 axios github 项目中打开了一个问题,但我想从你们那里了解一些想法。
谢谢。
最佳答案
您是否尝试过向配置对象添加“数据”字段?
let cookieJar;
const postBody = "MyBody=MyBodyContentGoesHere";
const url = "https://my-url.com";
return axios
.post(url,
postBody,
{
data: postBody,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
timeout: 10000,
jar: cookieJar,
withCredentials: true
}
);
关于node.js - Axios:请求 header 中缺少内容长度 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46934653/