i'm trying to allow another host (a local host, like javascript.dev
) to make a xhr to this host, it is an IIS7 and if i curl -I
it, this is the headers:
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Server: Microsoft-IIS/7.0
X-Powered-By: PHP/5.3.28
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS
Access-Control-Max-Age: 1000
Access-Control-Allow-Headers: *
X-Powered-By: ASP.NET
Date: Fri, 20 Jun 2014 12:09:33 GMT
this is the headers for curl -v -X OPTIONS
:
* About to connect() to www2.xxxxxxxxxxxx.com.br port 80 (#0)
* Trying 200.98.xxx.100...
* Connected to www2.xxxxxxxxxxxx.com.br (200.98.xxx.100) port 80 (#0)
> OPTIONS /jobs/xxxxxxx/user/ HTTP/1.1
> User-Agent: curl/7.30.0
> Host: www2.xxxxxxxxxxxx.com.br
> Accept: */*
>
< HTTP/1.1 200 OK
< Allow: OPTIONS, TRACE, GET, HEAD, POST
* Server Microsoft-IIS/7.0 is not blacklisted
< Server: Microsoft-IIS/7.0
< Public: OPTIONS, TRACE, GET, HEAD, POST
< X-Powered-By: ASP.NET
< Date: Fri, 20 Jun 2014 13:01:25 GMT
< Content-Length: 0
i used php to change the Access-Control-Allow-Origin
, but when i do the xhr, with or without jquery, this is the error i'm getting:
XMLHttpRequest cannot load http://www2.xxxxxxxx.com.br/jobs/xxxxxx/user/.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://javascript.dev' is therefore not allowed access.
to document, additional steps i made to solve:
i added code in the answer above to my web.config and get this error:
XMLHttpRequest cannot load http://www2.madeinweb.com.br/jobs/eminhasaude/user.
Request header field Content-Type is not allowed by Access-Control-Allow-Headers.
because Access-Control-Allow-Headers
don't accept wildcards *
. to solve:
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />