I've read many answers of preflight and CORS so please do not post links referencing what I should read. Many of the answers are from a server-perspective, but I am the client in this case. Do I set the origin header? My assumption is that this is a simple request, am I right?
req.open("POST", url, true); req.setRequestHeader( 'Content-Type', 'application/blahblah' ); req.setRequestHeader( 'Accept', 'application/blahblah' ); req.setRequestHeader("Authorization", "Basic " + btoa(user + ":" + pass)); req.send();
Yet its still not working, my error:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 500.
If you want to set the authorization header
req.setRequestHeader('Authorization','Basic ' + Base64StringOfUserColonPassword);
Solution:
var req = new XMLHttpRequest(); req.setRequestHeader('Authorization', 'Basic [base64 encoded password here]' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With