Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to allow ACCESS-CONTROL-ALLOW-ORIGIN aka cross-domain on wampserver

XMLHttpRequest cannot load https://webservice.com?param=hahah. Origin http://{domain} is not allowed by Access-Control-Allow-Origin.

I get this when I try to make a webservice call through wampserver, how could I enable this on wampserver?

or how may i just jsonP to obtain xml data without javascript throwing an error.

like image 491
user2167582 Avatar asked Aug 08 '13 22:08

user2167582


People also ask

How do I set Access-Control allow origin in CORS?

Simply add a header to your HttpServletResponse by calling addHeader : response. addHeader("Access-Control-Allow-Origin", "*");

How do I allow a domain in CORS?

To initiate a cross-origin request, a browser sends the request with an Origin: <domain> HTTP header, where <domain> is the domain that served the page. In response, the server sends Access-Control-Allow-Origin: <domain> , where <domain> is either a list of specific domains or a wildcard to allow all domains.

How do I bypass cross-origin request blocked?

You can bypass cross-domain request issues by using the Authorization Code Flow instead and making your calls directly from the server, which securely stores your client secret.

How does a server allow a cross-origin request from a domain?

CORS also relies on a mechanism by which browsers make a "preflight" request to the server hosting the cross-origin resource, in order to check that the server will permit the actual request. In that preflight, the browser sends headers that indicate the HTTP method and headers that will be used in the actual request.


2 Answers

You have to enable the headers module first, like so :

  • click on the wamp icon in your systray
  • go to Apache > Apache modules
  • check the option 'headers_module'

And then include this in your apache config:

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin: *
</IfModule>

(in httpd.conf or in the configuration of your vhost)

(Instead of the * you can also specify a specific domain)

like image 147
marty Avatar answered Sep 21 '22 22:09

marty


Hope this will solve your problem -

To add the CORS authorization to the header using Apache, simply add the following line inside either the , , or sections of your server config (usually located in a *.conf file, such as httpd.conf or apache.conf), or within a .htaccess file:

For all requests -

Header set Access-Control-Allow-Origin "*"

For trusted hosts -

Header set Access-Control-Allow-Origin "your-ip/domain-here"
like image 37
Dadaso Zanzane Avatar answered Sep 25 '22 22:09

Dadaso Zanzane