请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

6-7报错 Invalid character in header content ["Set-Cookie"]

报错:

(node:1540) UnhandledPromiseRejectionWarning: **TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Set-Cookie"]**
    at ServerResponse.setHeader (_http_outgoing.js:473:3)
    at userResult.then.userData (C:\code\02-code\01-blog01\app.js:108:25)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:1540) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1540) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are 
not handled will terminate the Node.js process with a non-zero exit code.

代码:

//处理user 路由
        const userResult = handleUserRouter(req,res)
        if (userResult) {
            userResult.then(userData => {
                if (needSetCookie){
                    // 后端修改cookie的值
                    console.log('userId',userId,`${getCookieExpires}`)
                    res.setHeader('Set-Cookie',`userId=${userId};path=/; httpOnly;expires=${getCookieExpires}`) //限制cookie修改 只允许后端修改
                }
                res.end(
                    JSON.stringify(userData)
                )
            })
            return 
        }

log打印内容:

userId 1570447599343_0.5098702049233002 ()=>{
    const d = new Date()
    d.setTime(d.getTime()+(24*60*60*1000))
    console.log('d.toGMTString()is ',d.toGMTString())
    return d.toGMTString()
}

正在回答 回答被采纳积分+3

插入代码

1回答

提问者 幻海尘封 2019-10-07 19:32:25

原因已找到。。。

0 回复 有任何疑惑可以回复我~
  • 双越 #1
    也可以自己写一下问题的答案哈,给其他同学分享。
    回复 有任何疑惑可以回复我~ 2019-10-07 20:34:10
  • 什么原因啊?我也遇到了
    回复 有任何疑惑可以回复我~ 2020-07-28 17:22:58
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号