首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Node.js: ECONNRESET何时提出多部分/表格-数据发布请求?

Node.js: ECONNRESET何时提出多部分/表格-数据发布请求?
EN

Stack Overflow用户
提问于 2022-04-01 15:53:26
回答 2查看 328关注 0票数 0

我得到了以下错误:

代码语言:javascript
运行
复制
(node:12268) [https://github.com/node-fetch/node-fetch/issues/1167] DeprecationWarning: form-data doesn't follow the spec and requires special treatment. Use alternative package
(Use `node --trace-deprecation ...` to show where the warning was created)
FetchError: request to https://api.nordigen.com/v2/report failed, reason: socket hang up
    at ClientRequest.<anonymous> (file:///home/doejohn/www/work/johndoe/backend/Scripts/nordigen-scripts/node_modules/node-fetch/src/index.js:108:11)
    at ClientRequest.emit (node:events:539:35)
    at TLSSocket.socketCloseListener (node:_http_client:427:11)
    at TLSSocket.emit (node:events:539:35)
    at node:net:709:12
    at TCP.done (node:_tls_wrap:582:7) {
  type: 'system',
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  erroredSysCall: undefined
}

当我执行以下请求时:

代码语言:javascript
运行
复制
  const data = new FormData();
  data.append("input", file);
  const init = {
    method: "POST",
    headers: {
      Authorization: `Bearer ${oauthToken}`,
    },
    body: data,
  };
  fetch("https://api.nordigen.com/v2/report", init)
    .then((res) => res.json())

我让它和Python一起工作得很好。但在将其转换为Node.js时,我似乎做错了什么。

代码语言:javascript
运行
复制
resReport = requests.post("https://api.nordigen.com/v2/report", files={'input': open('test2.json', 'rb')}, headers={"Authorization": f"Bearer {token}"})

node.js和python上的文件输入在磁盘上是相同的文件。我还检查了auth标记,它是正确的。

API上的文档具有以下curl请求,例如:

代码语言:javascript
运行
复制
curl -X POST \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
-F input=@example.json \
https://api.nordigen.com/v2/report

如何解决这个问题?

EN

Stack Overflow用户

发布于 2022-04-01 16:30:02

添加以下内容解决了这些问题。

代码语言:javascript
运行
复制
data.append(
'input',
fs.createReadStream(`./data/transactions_${process.env.GEBRUIKER}.json`)
)
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71709706

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档