RESTful webservice : how to set headers in java to accept XMLHttpRequest allowed by Access-Control-Allow-Origin

Read here about your issue CORS : http://enable-cors.org/ Check if this one help you in your getMsg() method: return Response.ok(output).header(“Access-Control-Allow-Origin”, “*”).build(); If above doesn’t work try to add Jersey filter to your service. Create filter class: package your.package; public class CORSFilter implements ContainerResponseFilter { @Override public ContainerResponse filter(ContainerRequest creq, ContainerResponse cresp) { cresp.getHttpHeaders().putSingle(“Access-Control-Allow-Origin”, “*”); cresp.getHttpHeaders().putSingle(“Access-Control-Allow-Credentials”, … Read more

CORS – Tomcat – Geoserver

I need to do the same to avoid the usage of a proxy in OpenLayers. Since I’m running Ubuntu 12.04, I’ve installed Tomcat 7.0.55, instead of the default 7.0.26 (installed from packages). To add CORS headers, I simply added to $CATALINA_HOME/conf/web.xml the following lines: <filter> <filter-name>CorsFilter</filter-name> <filter-class>org.apache.catalina.filters.CorsFilter</filter-class> <init-param> <param-name>cors.allowed.origins</param-name> <param-value>*</param-value> </init-param> </filter> <filter-mapping> <filter-name>CorsFilter</filter-name> <url-pattern>/*</url-pattern> … Read more

Internet Explorer 11 does not add the Origin header on a CORS request?

Internet Explorer’s definition of the “same origin” differs to the other browsers. See the IE Exceptions section of the MDN documentation on the same-origin policy: Internet Explorer has two major exceptions when it comes to same origin policy: Trust Zones: if both domains are in highly trusted zone e.g, corporate domains, then the same origin … Read more

CORS in ASP .NET MVC5

As described in here: Setting Access-Control-Allow-Origin in ASP.Net MVC – simplest possible method You should just create an action filter and set the headers there. You can use this action filter on your action methods wherever you want. public class AllowCrossSiteJsonAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { filterContext.RequestContext.HttpContext.Response.AddHeader(“Access-Control-Allow-Origin”, “*”); base.OnActionExecuting(filterContext); } } … Read more

How to allow Cross domain request in apache2

OS=GNU/Linux Debian Httpd=Apache/2.4.10 Change in /etc/apache2/apache2.conf <Directory /var/www/html> Order Allow,Deny Allow from all AllowOverride all Header set Access-Control-Allow-Origin “*” </Directory> Add/activate module a2enmod headers Restart service /etc/init.d/apache2 restart

Empty body in fetch POST request

The issue is mode: ‘no-cors’ From the documentation… Prevents the method from being anything other than HEAD, GET or POST, and the headers from being anything other than simple headers The simple content-type header restriction allows text/plain, application/x-www-form-urlencoded, and multipart/form-data This causes your nicely crafted Content-Type: application/json header to become content-type: text/plain (at least when … Read more