简体   繁体   English

访问REST URI数据时,AngularJS中出现CORS错误

[英]Getting CORS error in AngularJS when accessing data form REST URI

XMLHttpRequest cannot load http://hfdvcbapp01.vm.itg.corp.us.shldcorp.com:8180/cnb/cnb/report/summary?Company=IT . XMLHttpRequest无法加载http://hfdvcbapp01.vm.itg.corp.us.shldcorp.com:8180/cnb/cnb/report/summary?Company=IT No 'Access-Control-Allow-Origin' header is present on the requested resource. 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin ' http://127.0.0.1:64033 ' is therefore not allowed access. 因此,不允许访问来源' http://127.0.0.1:64033 '。

I am getting this error when i am trying to load data from json which situated at the server.How can i resolve this. 我尝试从位于服务器的json加载数据时遇到此错误,我该如何解决。

Your api is not returning header 您的api不返回标头

Access-Control-Allow-Origin: http://yourdomain.com

to allow specific domain 允许特定领域

or 要么

Access-Control-Allow-Origin: *

to allow all 允许所有

PS. PS。 Also make sure that headers are actually there. 还要确保标题实际上在那儿。 Pay attention that CORS actually send 2 requests 1 will be OPTIONS , second will be actual request so if you return headers only on GET or POST it wont work. 请注意,CORS实际上发送2个请求,1将是OPTIONS ,第二个将是实际请求,因此,如果仅在GETPOST上返回标头,则它将不起作用。 To check it in chrome presss f12, go to network and do you requests make sure that header is there Read more 要在镀铬机中按f12进行检查,请转至网络,您是否要求确保页眉在此阅读更多

Access-Control-Allow-Origin header should be set in the response, 响应中应设置Access-Control-Allow-Origin标头,

if it is not from the same origin of the URL it was sent from, the header should be set from the respone - meaning - the server responding to the request in youre case - http://hfdvcbapp01.vm.itg.corp.us.shldcorp.com:8180 , if the server is under youre control just handle it, if its an outside service you should request this. 如果它不是来自发送它的URL的同一来源,则应从响应设置标头-这意味着-在您的情况下服务器响应请求-http: //hfdvcbapp01.vm.itg.corp.us .shldcorp.com:8180 ,如果服务器在您的控制之下, 则只处理它,如果它是外部服务,则应请求此服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM