【发布时间】:2011-10-19 15:12:36
【问题描述】:
第一次使用 NodeJS(是的,它很棒)并且还使用了 Express。让网络应用程序/服务运行良好,但在尝试发出多个 http 请求时遇到了问题。这是该应用程序如何导致 2 个 http 请求的视频 - http://screencast.com/t/yFKdIajs0XD - 如您所见,我单击“文章”它加载了一个 rss 提要,然后单击视频并加载了一个 youtube 提要-两者都可以正常工作,但在第二个之后调用它会引发异常。当我使用节点的 http 模块尝试两个单独的 http 请求时,我得到以下信息:
http.js:527
throw new Error("Can't set headers after they are sent.");
^
Error: Can't set headers after they are sent.
at ServerResponse.<anonymous> (http.js:527:11)
at ServerResponse.setHeader (/Users/rickblalock/node/auti_node/node_modules/express/node_modules/connect/lib/patch.js:47:22)
at /Users/rickblalock/node/auti_node/node_modules/express/node_modules/connect/lib/middleware/errorHandler.js:72:19
at [object Object].<anonymous> (fs.js:107:5)
at [object Object].emit (events.js:61:17)
at afterRead (fs.js:878:12)
at wrapper (fs.js:245:17)
此处提供的示例代码: 使用我的控制器模块来呈现请求 - http://pastie.org/2317698 选项卡之一(文章选项卡) - 视频代码相同减去引用视频源:http://pastie.org/2317731
【问题讨论】:
标签: http node.js request express