Fehlerbehebung bei CORS in Play Framework 2.4.x
Ich verwende eine Java Play Framework 2.4.x-Webanwendung, die eine JSON / HTTP-API bereitstellt. Wenn ich mein Front-End-HTML / JS @ starfile:///Users/nize/tmp/index.html
Aufruf der API aufhttp://localhost:9000
chrome shows
XMLHttpRequest cannot load http://localhost:9000.
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 403.
Ich habe die Web-App gemäß den Anweisungen in @ konfigurierPlay Framework 2.4.x CORS-Dokumentation:
Aktualisieren zubuild.sbt
Klasse hinzugefügtFilters.java
zum Stammverzeichnis des Projekts (auch ausprobiert/app
)Fügte die folgende Zeilengruppe zum @ hinapplication.conf
play.filters.cors {allowedOrigins = ["*", "http: // localhost "] #allowedHttpMethods = [" GET "," POST "] #allowedHttpHeaders = [" Accept "] #preflightMaxAge = 3 Tage}
Was vermisse ich
Bearbeiten Die Symptome sehen gleich oder ähnlich aus wie Andere sehr ähnliche Stackoverflow-Post. Dieses Problem wurde durch Neukonfiguration von Cisco AnyConnect VPN behoben, das auf dem Computer installiert war. Ich habe diese Software jedoch nicht installiert.