代码之家  ›  专栏  ›  技术社区  ›  Nick Lee

跨源api get请求的响应中未显示Cookie

  •  0
  • Nick Lee  · 技术社区  · 7 年前

    更新:当我转到url中的api路由时,cookie被设置,但在使用javascript请求时没有设置。

    router.route("/:id").get(
        function(req,res){
            res.setHeader('Set-Cookie', 'beer=sour');
            console.log('response: ', res);
            res.sendStatus(200)
        })
    

    或者使用express,函数:

    function(req,res){
        res.cookie('name', 'tobi', {});
         res.sendStatus(200)
    }
    

    当我在发送之前控制台将响应记录到服务器时,它似乎会设置此值。

    { 'x-powered-by': [ 'X-Powered-By', 'Express' ],
     'set-cookie':
      [ 'Set-Cookie',
        'name=tobi; Domain=.example.com; Path=/admin; Secure' ] } }
    

    根据客户的回复,我找不到饼干!

    componentDidMount(){
        axios.get(`http://localhost:3000/authentication/${this.props.match.params.id}`)
        .then(function(data){
          console.log('data: ', data)
        })
      }
    

    日志:

     headers:
            Accept: "application/json, text/plain, */*"
            __proto__: Object
    

    也许我假设它在“headers”下面,因为逻辑上是有意义的。但在响应对象的其他位置找不到cookie。

    我也在控制台的document.cookie下查看过。

    0 回复  |  直到 7 年前