mein Szenario von zwei Webserver einem lokalen und einem entfernten besteht.Access-Control-Allow-Origin AngularJS php
Lokale Webserver (Apache) verarbeiten eine Web-App, in der ich eine Ajax-Anfrage an Remote-Webserver (Lighttpd) machen möchte.
Ajax Anfrage Verwendung angularjs $ http.
var req = {
method: 'POST',
url: 'http://url/myphp.php',
headers: {
'Authorization': 'Basic ' + btoa('username:password'),
'Content-Type': 'application/x-www-form-urlencoded'
},
xhrFields: {
withCredentials: true
},
crossDomain: true,
data: xmlString
}
$http(req).then(function() {
console.log("OK!");
});
Remote-PHP-Skript ist:
<?php
echo "You have CORS!";
?>
Leider bekam ich ein
401 Unhauthorized
XMLHttpRequest cannot load http://url/myphp.php. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8888' is therefore not allowed access. The response had HTTP status code 401.
Remote-Web-Server-Authentifizierungsmodus aktivieren und CORS Anforderung konfiguriert .htpasswd hat.
ein Stück lighttpd.conf
setenv.add-response-header = ("Access-Control-Allow-Origin" => "*")
Welchen Browser Sie @gravi verwenden? – noahdotgansallo
Sowohl Chrome und Firefox – gravi
Ich hatte das gleiche Problem, und offenbar blockiert Chrom gerade alle diese Arten von Anfragen, trotz der Header – noahdotgansallo