AngularJS httpget调用被阻塞,原因是CORS预检频道没有成功

时间:2016-06-08 19:23:58

标签: javascript jquery angularjs cors http-get

我正在尝试对特定的API调用执行httpget方法。 邮差调用工作正常但是当我试图在角度控制器中进行调用时,这就是我得到的:

"阻止跨源请求:同源策略禁止在http://apidev.facu.la/api/json/infotag/search/?criteria=&infotagType=book&companyid=2读取远程资源。 (原因:CORS预检频道没有成功)。"

这是我正在制作的httpget电话:

$http({
                method: 'GET',
                dataType: "json",
                url: 'http://apidev.facu.la/api/json/infotag/search/?criteria=&infotagType=book&companyid=2',
                headers: {
                    "Content-Type": "json",
                    "Access-Control-Request-Headers": "Origin, X-Requested-With, Content-Type, Access-Control-Allow-Origin",
                    "Access-Control-Request-Methods": "PUT, GET, POST, DELETE, OPTIONS",
                }
            }).then(function successCallback(response) {
               alert('ok');
            }, function errorCallback(response) {
                alert('error');
            });

API端的CORS设置:

 <customHeaders>
        <remove name="X-Powered-By" />
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, OPTIONS, HEAD" />
        <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Authorization, Accept" />
        <add name="Access-Control-Allow-Credentials" value="true" />
        <add name="X-Powered-By" value="yuca.pro" />
      </customHeaders>

知道我错过了什么吗?

提前致谢,Laziale

0 个答案:

没有答案