我正在尝试从在 127.0.0.1:3000 上运行的反应应用程序将授权标头发送到在 127.0.0.1:8888 上运行的 API 端点。
var data = new URLSearchParams();
data.append('code', code);
fetch('http://localhost:8888/users/verifyEmail', {
method: 'POST',
credentials: 'include',
headers: {
'authorization': 'Bearer '+ bearer,
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
},
body: data
})
请求被设置为 aOPTIONS而不是 a POST。
在接受请求的端点中,我设置了标头
header('Access-Control-Allow-Origin: http://localhost:8888/');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: authorization, bearer, content-type, accept');
