AWS API网关在OPTIONS请求使用fetch调用GET API时发送403错误,并从fiddler获得以下详细信息:
HTTP/1.1 403 Forbidden
Date: Fri, 23 Sep 2022 11:50:57 GMT
Content-Type: application/json
Content-Length: 42
Connection: keep-alive
x-amzn-RequestId: 02883556-5b3b-4af7-8c3a-3d561f2e0557
x-amzn-ErrorType: MissingAuthenticationTokenException
x-amz-apigw-id: Y6WFM7rPEF9iQ=
{"message":"Missing Authentication Token"}
而相同的url适用于Axios请求,确切的请求细节已由fiddler验证。
Fetch请求缺少模式属性,默认为无不允许选项请求的cors,将模式设置为cors有效。
return fetch(`${process.env.URL}edit_session/${documentId}?${new URLSearchParams({
edit_token: editToken,
action: 'clear'
})}`, {
method: 'GET',
keepalive: true,
headers,
mode: 'cors',
cache: 'no-cache'
});