I am trying to make a GET/POST Request to my Wordpress REST API using Authorization Headers but in response i am getting
preflight request doesn't pass access control check: It does not have HTTP ok status.
I am using JWT Authentication for WP-API for Authentication and tried almost every possible option found on the internet but no luck.
Have a look at my current .htaccess configurations
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]
</IfModule>
<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
<IfModule mod_setenvif.c>
SetEnvIf Origin "^(http://localhost:3000)$" CORS=$0
</IfModule>
Header set Access-Control-Allow-Origin %{CORS}e env=CORS
Header set Access-Control-Allow-Credentials "true" env=CORS
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS, HEAD" env=CORS
Header set Access-Control-Allow-Headers "*" env=CORS
Header set Access-Control-Expose-Headers "*" env=CORS
<FilesMatch "\.(php|html)$">
</FilesMatch>
</IfModule>
I am getting this error when the request is made from axios
Access to XMLHttpRequest at 'HIDDEN_SERVER_ADDRESS' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
In PostMan the calls are working fine and giving desired results.
RewriteRule ^(.*)$ $1 [R=200,L]– that only tries to set the status code at this point, but the request still gets passed through to whatever script handles this URL route - so if that script then issues a different status code, it will simply overwrite this. - misorude