我正在从react应用程序中进行访存删除,删除操作由aws lambda(python flask)处理。
反应获取代码
fetch(url, {
'method' : 'DELETE',
headers: {
'Accept': '*',
'Access-Control-Request-Method': 'DELETE',
'Access-Control-Request-Headers': 'Content-Type',
"Access-Control-Allow-Methods": "DELETE",
"Content-Type": "application/json",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Max-Age": "86400"
}
}).then(response => Promise( response.json()))
.then(( responseJson) => {
console.log("response json is " + responseJson)
})
.catch(error => {
console.log(error)
}
)
使用python来lambda
headers = {
"Access-Control-Allow-Methods": "GET, POST, PATCH, PUT, DELETE, OPTIONS",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
}
return testjson, 200, headers
错误:
访问CORS策略已阻止从原点“ https://xxx.amazonaws.com/Prod/api/2516”获取“ http://localhost:3000”的访问权限:Access-Control-Allow-不允许请求标头字段access-control-allow-headers-飞行前响应中出现标题。