gpt4 book ai didi

node.js - 发送后无法设置 header 。在验证 header 处

转载 作者:太空宇宙 更新时间:2023-11-04 00:00:58 25 4
gpt4 key购买 nike

在使用 API 时,我遇到了以下问题。

请告诉我出现此错误的原因:

api runnging on port 5000:
events.js:183
throw er; // Unhandled 'error' event
^

Error: Can't set headers after they are sent.
at validateHeader (_http_outgoing.js:491:11)
at ServerResponse.setHeader (_http_outgoing.js:498:3
)
at ServerResponse.header (/Users/krishnamurthys/ecli
pse-workspace/vue_demo/node_modules/express/lib/response
.js:767:10)
at ServerResponse.send (/Users/krishnamurthys/eclips
e-workspace/vue_demo/node_modules/express/lib/response.j
s:170:12)
at ServerResponse.json (/Users/krishnamurthys/eclips
e-workspace/vue_demo/node_modules/express/lib/response.j
s:267:15)
at ServerResponse.send (/Users/krishnamurthys/eclips
e-workspace/vue_demo/node_modules/express/lib/response.j
s:158:21)
at appointment.save (/Users/krishnamurthys/eclipse-w
orkspace/vue_demo/api/server.js:30:16)
at /Users/krishnamurthys/eclipse-workspace/vue_demo/
node_modules/mongoose/lib/model.js:4528:16
at $__save.error (/Users/krishnamurthys/eclipse-work
space/vue_demo/node_modules/mongoose/lib/model.js:435:16
)
at /Users/krishnamurthys/eclipse-workspace/vue_demo/
node_modules/kareem/index.js:246:48
at next (/Users/krishnamurthys/eclipse-workspace/vue
_demo/node_modules/kareem/index.js:167:27)
at next (/Users/krishnamurthys/eclipse-workspace/vue
_demo/node_modules/kareem/index.js:169:9)
at Kareem.execPost (/Users/krishnamurthys/eclipse-wo
rkspace/vue_demo/node_modules/kareem/index.js:217:3)
at _handleWrapError (/Users/krishnamurthys/eclipse-w
orkspace/vue_demo/node_modules/kareem/index.js:245:21)
at /Users/krishnamurthys/eclipse-workspace/vue_demo/
node_modules/kareem/index.js:272:14
at _next (/Users/krishnamurthys/eclipse-workspace/vu
e_demo/node_modules/kareem/index.js:94:14)
[nodemon] app crashed - waiting for file changes before
starting...
[nodemon] restarting due to changes...
[nodemon] starting `node api/server.js`
api runnging on port 5000:

最佳答案

当您有如下代码时会导致此错误:

//say true
if(true){
//...
res.send();
}
res.send();

关于node.js - 发送后无法设置 header 。在验证 header 处,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54722954/

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