_http_outgoing.js:360 throw new TypeError('The header content contains invalid characters');

E:\nodetest>node server.js

_http_outgoing.js:360

    throw new TypeError('The header content contains invalid characters');

    ^

TypeError: The header content contains invalid characters

    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:360:11)

    at E:\nodetest\node_modules\express-static\index.js:48:11

    at FSReqWrap.oncomplete (fs.js:123:15)

这个错误是什么原因?求大神指教

源码:

const express=require('express');

const static=require('express-static');

const cookieParser=require('cookie-parser');

const cookieSession=require('cookie-session');

const bodyParser=require('body-parser');

const multer=require('multer');

const consolidate=require('consolidate');

const mysql=require('mysql');


//连接池

const db=mysql.createPool({host: 'localhost', user: 'root', password: 'yue638', database: 'blog'});


var server=express();

server.listen(8080);


//1.解析cookie

server.use(cookieParser('sdfasl43kjoifguokn4lkhoifo4k3'));


//2.使用session

var arr=[];

for(var i=0;i<100000;i++){

  arr.push('keys_'+Math.random());

}

server.use(cookieSession({name: 'zns_sess_id', keys: arr, maxAge: 20*3600*1000}));


//3.post数据

server.use(bodyParser.urlencoded({extended: false}));

server.use(multer({dest: './www/upload'}).any());


//4.配置模板引擎

//输出什么东西

server.set('view engine', 'html');

//模板文件放在哪儿

server.set('views', './template');

//哪种模板引擎

server.engine('html', consolidate.ejs);


//接收用户请求

server.get('/', (req, res)=>{

  //查询banner的东西

  db.query("SELECT * FROM banner_table", (err, data)=>{

    if(err){

      console.log(err);

      res.status(500).send('database error').end();

    }else{

      console.log(data);

      res.render('index.ejs', {banners: data});

    }

  });

});

//4.static数据

server.use(static('./www'));


kathria
浏览 3423回答 3
3回答

加咖啡喵

请问我显示Cannot GET /index.html是为什么呢? 代码和你是一样的
打开App,查看更多内容
随时随地看视频慕课网APP