Axios手动设置Content-Length,nodeJS

问题描述 投票:0回答:1

是否可以在nodeJS中发送发布请求并指定内容长度。

我尝试过(使用axios):

let data = `Some text data...........`;

let form = await Axios.post(
    "url.......",
    data,
    {
        headers: {
            Authentication: "token.....",
            "Content-Type": "multipart/form-data; boundary=c9236fb18bed42c49590f58f8cc327e3",
            //set content-length manually 
            "Content-Length": "268"
        }
    }
).catch(e => e);

它不起作用,长度自动设置为我通过的值以外的值。

我正在使用axios,但愿意使用任何其他方式从nodeJS进行发布。

node.js axios content-length http-content-length
1个回答
0
投票

如果存在数据,它将设置根据数据计算得出的长度,因此,即使您传递标头content-length,也会被代码覆盖:enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.