CORS requests with session/cookie

后端 未结 2 751
伪装坚强ぢ
伪装坚强ぢ 2020-12-19 08:06

My application has a PHP server and a client (a JS single-page app). They are separate projects and deployed in different domains. The client consumes a RESTful API exposed

相关标签:
2条回答
  • 2020-12-19 08:34

    I thought that once the session was created the browser would automatically send the right Cookie header in the asynchronous API calls

    Not for cross-domain requests for CORS-enabled ressources (which seems to be the case here, if I understand your described setup correctly.)

    To make that happen, you need to set the withCredentials flag.

    0 讨论(0)
  • 2020-12-19 08:35

    You must set withCredentials to true for cross-origin XHR requests to include cookies.

    The CORS response must also say Access-Control-Allow-Credentials: true (which is why widthCredentials defaults to false).

    0 讨论(0)
提交回复
热议问题