我正在使用falcon_cors在python中创建宁静的服务。如果用户界面发送来自不同域的http请求,浏览器将首先发送OPTIONS请求。但我在浏览器上得到以下错误:如何通过falcon_cors启用`OPTIONS`请求?
XMLHttpRequest无法加载http://localhost:8000/user/。对 预检请求的响应未通过访问控制检查:响应中的'Access-Control-Allow-Credentials'标头的值为'',当请求的凭证模式为'include'时,其中 必须为'true' 。 原因'http://localhost:4200'因此不允许访问。由XMLHttpRequest发起的请求的凭证模式 由withCredentials属性控制。
我已经搜索到我需要允许来自后端的OPTIONS来处理这个请求。所以,我写我的代码如下:
f_cors = falcon_cors.CORS(allow_origins_list=[
'http://localhost:4200',
'http://127.0.0.1:4200',
],
allow_all_headers=True, allow_all_methods=True)
app_pre_beaker = falcon.API(middleware=[
f_cors.middleware
])
我已经创造falcon_cors
指定allow_all_methods=True
但我仍然得到同样的错误。我还需要更新哪些内容?
是的,你是对的。在'falcon_cors.CORS'调用中添加'allow_credentials_all_origins = True'后,它运行良好。 –