Skip to main content

Request header field Access-Control-Allow-Headers is not allowed by itself in preflight response

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

Popular posts from this blog

How Become a web developer ?

There is a huge need for web developers these days, and there are many job posts in the IT industry where a web developer is needed. How Become a web developer ? Basic Requirement Mid Configuration PC / Laptop. Basic Computer Knowledge. VS Code Software Installed. Basic Leaning Paths  : HTML  stand for Hyper text markup language. that use for basic structure of webpage. like : heading, link, image, video, list, table and form. that help to made basic structure of webpage. CSS stand for cascading styling sheet. That use for styling of  HTML structure. Like Colouring, background, Border, Shadow, width & height and much more. JAVASCRIPT is  the programming language of the Web. JavaScript is easy to learn. that move useful of web development like  button click event, HTML element change styling & content, In short work JAVASCRIPT is Control hole HTML structure & modify those element as well as Element Stying on specific events. In 2025 should b...