I'm sending an Angular http request with headers
let auth = 'user:pass';
const httpOptions = new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded',
'Access-Control-Request-Headers': 'Content-Type, Authorization',
'Authorization': 'Basic ' + btoa(auth)
});
this.http.get<any>(backendUrl, { headers: httpOptions })
on my php backend (that is protected with htaccess password) i have in the first lines of the .htaccess file:
Header set Access-Control-Allow-Headers "Content-Type, Authorization"
Header set Access-Control-Allow-Origin "*"
Header set Connection keep-alive
Header set Access-Control-Max-Age "1000"
SetEnvIf Host myproject.localhost passreq
AuthType Basic
AuthName "Password Required"
AuthUserFile "C:\wamp64\www\my-project\.htpasswd"
Require valid-user
Order allow,deny
Allow from all
Deny from env=passreq
Satisfy any
It works without any problem if I use direct backendUrl and enter the login and pass manually. It works without any problem if I use postman, givin the login and pass. In both case i have a response 200 But when i try via the angular component I have
Access to XMLHttpRequest at 'http://my-project.localhost/' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Some one can tell me where is the problem? i'm not able to find. thanks in advance...