我正在尝试使用 Axios HTTP 请求调用来验证 Express API 后端。
我能够在响应标头中看到“Set-Cookie”,但未设置 cookie。是否可以通过axios HTTP调用设置cookie?
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 355
Content-Type: application/json; charset=utf-8
Date: Fri, 28 Sep 2018 05:59:01 GMT
ETag: W/"163-PAMc87SVHWkdimTJca7oRw"
Set-Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...; Max-Age=3.6; Path=/; Expires=Fri, 28 Sep 2018 05:59:04 GMT; HttpOnly
X-Powered-By: Express
试试这个!
axios.get('your_url', {withCredentials: true}); //for GET
axios.post('your_url', data, {withCredentials: true}); //for POST
axios.put('your_url', data, {withCredentials: true}); //for PUT
axios.delete('your_url', data, {withCredentials: true}); //for DELETE
有关 axios 文档的更多信息:
“withCredentials 指示是否应使用凭据发出跨站点访问控制请求”-https://github.com/axios/axios
有关 withCredentials 的更多详细信息:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)