最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

发送后无法设置标头。在验证标题

IT培训 admin 6浏览 0评论

发送后无法设置标头。在验证标题

在点击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();

发送后无法设置标头。在验证标题

在点击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();
发布评论

评论列表 (0)

  1. 暂无评论