b_ant_tech
@b_ant_tech
Thu, Mar 10, 2022 3:00 AM
CORS
b_ant_tech
@b_ant_tech
Thu, Mar 10, 2022 3:00 AM
Cross-Origin Resource Sharing (CORS)
b_ant_tech
@b_ant_tech
Thu, Mar 10, 2022 3:16 AM
Share credentials with CORS
b_ant_tech
@b_ant_tech
Thu, Mar 10, 2022 3:16 AM
If you want to send cookies when using CORS (which could identify the sender), you need to add additional headers to the request and response.
b_ant_tech
@b_ant_tech
Thu, Mar 10, 2022 3:16 AM
Request #
Add credentials: 'include' to the fetch options like below. This will include the cookie with the request.
b_ant_tech
@b_ant_tech
Thu, Mar 10, 2022 3:17 AM
Response #
Access-Control-Allow-Origin must be set to a specific origin (no wildcard using *) and must set Access-Control-Allow-Credentials to true.
b_ant_tech
@b_ant_tech
Thu, Mar 10, 2022 3:18 AM
Preflight requests for complex HTTP calls #
b_ant_tech
@b_ant_tech
Thu, Mar 10, 2022 3:19 AM
The CORS specification defines a complex request as
b_ant_tech
@b_ant_tech
Thu, Mar 10, 2022 3:19 AM
◆A request that uses methods other than GET, POST, or HEAD
b_ant_tech
@b_ant_tech
Thu, Mar 10, 2022 3:19 AM
◆A request that includes headers other than Accept, Accept-Language or Content-Language
b_ant_tech
@b_ant_tech
Thu, Mar 10, 2022 3:20 AM
◆A request that has a Content-Type header other than application/x-www-form-urlencoded, multipart/form-data, or text/plain
b_ant_tech
@b_ant_tech
Thu, Mar 10, 2022 3:20 AM
Browsers create a preflight request if it is needed. It's an
OPTIONS
request like below and is sent before the actual request message.
b_ant_tech
@b_ant_tech
Thu, Mar 10, 2022 3:22 AM
The server response can also include an
Access-Control-Max-Age
header to specify the duration (in seconds) to cache preflight results so
the client does not need to make a preflight request every time it sends a complex request
.
b_ant_tech
@b_ant_tech
Thu, Mar 10, 2022 3:27 AM
CORS只存在於瀏覽器,因為這是由於瀏覽器雖然收到正常回覆但阻擋
載入新的回覆
Add credentials: 'include' to the fetch options like below. This will include the cookie with the request.
Access-Control-Allow-Origin must be set to a specific origin (no wildcard using *) and must set Access-Control-Allow-Credentials to true.