问题描述:系统:Windows 7 x64Node.js版本:版本是:v4.2.4 LTS安装过程参考:《Node.js入门》Windows 7下Node.js Web开发环境搭建笔记一段后端模拟HTTP请求的代码出现以下错误:Error: Can't set headers after they are sent.如下图:相关代码:app.get('/trans', function (req, res) {
var body = '';
//这是需要提交的数据
params = { 'source':'en', 'target':'es', 'text':'hello' }
var data = qs.stringify(params);
http.get("https://gateway.watsonplatform.net/language-translation/api/v2/translate?" + data, function(gres) {
console.log("Got response: " + gres);
gres.on('data',function(d){
body += d;
}).on('end', function(){
//console.log(gres.
...
继续阅读
(44)