Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法设置cookie的过期日期_Javascript_Django_Cookies_Request - Fatal编程技术网

Javascript 无法设置cookie的过期日期

Javascript 无法设置cookie的过期日期,javascript,django,cookies,request,Javascript,Django,Cookies,Request,我正在用ReactJS和Djangowebapi开发一个web应用程序。我的问题是: 我向API发送一个请求,该请求返回一个令牌,我将使用该令牌发送需要身份验证的请求,以及令牌的过期日期 答案是这样的: { name: "Elliot", id: 1, token: "<the token here>" expires: "2018-04-29T17:00:00.000Z" } 它将失效日期设置为1969年。有人知道为什么吗 详情: 我看了看日期是否已经过

我正在用
ReactJS
Django
webapi开发一个web应用程序。我的问题是:

我向API发送一个请求,该请求返回一个令牌,我将使用该令牌发送需要身份验证的请求,以及令牌的过期日期

答案是这样的:

{
   name: "Elliot",
   id: 1,
   token: "<the token here>"
   expires: "2018-04-29T17:00:00.000Z"
}
它将失效日期设置为1969年。有人知道为什么吗

详情:

  • 我看了看日期是否已经过期,但是,它没有过期。从现在起,总有3个小时

    • 问题解决了!我认为日期的格式是对的,但事实并非如此。然后,我使用
      toutString()
      转换了日期,如下所示:

      const expires = new Date(response.expires)
      document.cookie = `token=${response.token};expires=${expires.toUTCString()}`
      
      希望它能帮助别人

      const expires = new Date(response.expires)
      document.cookie = `token=${response.token};expires=${expires.toUTCString()}`