3

I'm trying to make Wildfly allow Cross-Origin requests, in order to be able to send requests to localhost using local JavaScript code.

Here's a request I'm making via JavaScript:

var request = new XMLHttpRequest();  

request.open("GET", requestUrl);  
request.setRequestHeader("Access-Control-Allow-Origin", "*");  
request.send();  

An error is thrown in the dev console when testing in Chrome.

XMLHttpRequest cannot load http://localhost:8080/.... Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.

The request fails on Firefox as well, although no error is thrown in this case.

I modified my standalone.xml and restarted Wildfly according to this answer, to no avail:

CORS: AngularJS + Resteasy 3 + Wildfly

I even tried creating a filter class according to this answer, it didn't help as well:

How to enable Cross domain requests on JAX-RS web services?

I didn't change any configurations to include this class however, in case such a thing is required for it to work.

Community
  • 1
  • 1
Royi Bernthal
  • 882
  • 4
  • 17
  • 45
  • You are setting wrong header in the `XMLHttpRequest` object, see http://stackoverflow.com/questions/23272611/make-cors-ajax-requests-using-xmlhttprequest – Federico Sierra Oct 12 '16 at 14:40
  • You are right. I don't even need to set headers in JS, as soon as I removed that irrelevant header everything worked properly. Thank you – Royi Bernthal Oct 12 '16 at 22:48

0 Answers0