Skip to content

Error: Can't set headers after they are sent. #8

Description

@Kaviilee

记录一下最近遇到的问题。

问题背景

一个需求,需要在 nodejs 端进行带 cookie 的请求。请求返回后,需要将另外一个的 cookie 通过 set-Cookie 设置给 client

解决方案

把第一个请求剥离出来,不要进行嵌套请求,即不要在 callback 里面进行 set-Cookie 操作。
可以尝试将 nodejs 端的请求封装在 Promise 内,利用 async/await 获取到数据之后再进行后续的操作。

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions