飞行前响应中的Access-Control-Allow-Headers不允许请求标头字段… [英] Request header field … is not allowed by Access-Control-Allow-Headers in preflight response
问题描述
我使用django作为后端使用react / express。
我正在尝试集成s3精细上载器,并且我遇到了这个问题:Access-Control-Allow不允许请求标头字段Cache-Control -在尝试从django中获取签名时,在发帖请求中,标题在预检响应中。
通常,我使用fetch在代码中提出所有请求,但在这里我使用包 https://github.com/FineUploader/react-fine-uploader 并利用xhr吗?有人遇到了这个问题
I use react/express with django as backend.
I am trying to integrate s3 fine uploader and i am getting this issue :Request header field Cache-Control is not allowed by Access-Control-Allow-Headers in preflight response when trying to get signature from django,in a post request.
Normally i make all my request in code using fetch but here i make use of the package https://github.com/FineUploader/react-fine-uploader and it make use of xhr ? any one ran into this issue
简介
错误:请求标头字段缓存飞行前响应中,Access-Control-Allow-Header不允许使用-Control。
ERROR: Request header field Cache-Control is not allowed by Access-Control-Allow-Headers in preflight response.
前端:反应/表达/ Webpack
后端:Dajngo < br>
环境:本地(django服务器,反应本地api)
原因:xhr?
Frontend:React/express/webpack
Backend:Dajngo
Environment:Local (django server,react local api)
cause: xhr?
推荐答案
您的问题出在后端。似乎您要使用的api是用Django编写的。
Your problem is in the backend. Seems like the api you are trying to use is written in django.
api所有者需要将该标头明确添加到CORS_ALLOW_HEADERS设置中。上传图片时,Content-Disposition标头存在相同的问题。这是我的设置:
The api owner needs to explicitly add that header into the CORS_ALLOW_HEADERS settings. I had the same issue with the Content-Disposition header while uploading images. This is my settings:
CORS_ALLOW_HEADERS = ('content-disposition', 'accept-encoding',
'content-type', 'accept', 'origin', 'authorization')
在您的情况下,设置需要包含缓存控制。
In your case, that setting needs to include 'cache-control'.
这篇关于飞行前响应中的Access-Control-Allow-Headers不允许请求标头字段…的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!