gpt4 book ai didi

node.js - Axios 手动设置 Content-Length,nodeJS

转载 作者:行者123 更新时间:2023-12-05 09:11:31 25 4
gpt4 key购买 nike

有没有办法在 nodeJS 中发送 post 请求并指定内容长度。

我试过(使用 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 发帖。

最佳答案

由于信誉不佳,我无法添加评论,但 Sandeep Patel 关于 Axios 的部分回答已过时。您可以手动设置 Content-Length。如果存在 content-length header ,Axios 将不会覆盖 Content-Length:

// Add Content-Length header if data exists
if (!headerNames['content-length']) {
headers['Content-Length'] = data.length;
}

来源:https://github.com/axios/axios/blob/main/lib/adapters/http.js#L209-L213

所以在你的情况下会是:

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

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

关于node.js - Axios 手动设置 Content-Length,nodeJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59954053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com