The error "Request header field Access-Control-Allow-Headers is not allowed by itself in preflight response" arises when a preflight (OPTIONS) request, sent to check if a cross-origin request is safe, doesn't explicitly list all the custom headers the actual request will use in the Access-Control-Allow-Headers response header. This means the server needs to be configured to allow the specific headers being used in the actual request.
Resolve in Framework / core level
in Server side handle option request and return with header.
- Header always set Access-Control-Allow-Origin "*"
- Header always set Access-Control-Allow-Methods "*"
- Header always set Access-Control-Allow-Headers "*"
Resolve in Server level
change in .htaccess file
<IfModule mod_headers.c>
<If "%{REQUEST_METHOD} == 'OPTIONS'">
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Allow-Methods "*"
Header always set Access-Control-Allow-Headers "*"
Header always set Access-Control-Max-Age "86400"
Header always set Access-Control-Allow-Credentials "true"
Header always set Content-Length "0"
Header always set Content-Type "text/plain"
Header always set Cache-Control "no-cache, no-store, must-revalidate"
Header always set Pragma "no-cache"
Header always set Expires "0"
# Add other headers as needed
</If>
</IfModule>
Comments