我的router/user.js里面代码:
if(method === 'GET' &&path === '/api/user/login'){
const {username, password} = req.query
console.log(username)
const reslut = login(username, password)
return reslut.then((obj)=>{
console.log(obj)
if(obj.username){
//操作cookie,给用户写入cookie (path改为 根目录,所有的路由都会生效)
res.setHeader('Set-Cookie', `username=${obj.username};path=/`);
return new SuccessModel('登录成功')
} else{
return new ErrorModel('登录失败,账号密码不匹配')
}
})
}
控制台报错:
(node:9540) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_CHAR]: Invalid character in header content [“Set-Cookie”]
at ServerResponse.setHeader (_http_outgoing.js:521:3)
我看了和老师写的是一样的呢,它说我设置了一个无效header, 的这是什么原因报错呢?