Firefox中阻止跨源请求

[英]Cross-Origin Request Blocked in Firefox


When we are accessing data from server using angularjs we are getting a CORSE-Error

当我们使用angularjs从服务器访问数据时,我们得到一个CORSE-Error

Our code:

var app = angular.module("app", []);
app.controller("Ctrl", function($scope, $http) {
    $scope.survey = true;
    $scope.question = false;
        $http.get("http://localhost:8081/NxtLife_Demo/getsurveyall").success(function(data) {
        $scope.surveys = data;
    });
});

Controller-code:

@RequestMapping(value = "/getsurveyall", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String getSurveyAll() throws JsonProcessingException {
    Set<SurveyRecords> records = new HashSet<SurveyRecords>();
    records.addAll(surveyService.getSurveyAll());
    return new ObjectMapper().writeValueAsString(records);
}

The Error Message:

错误消息:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8081/NxtLife_Demo/getsurveyall. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

跨源请求已阻止:同源策略禁止在http:// localhost:8081 / NxtLife_Demo / getsurveyall上读取远程资源。 (原因:缺少CORS标题'Access-Control-Allow-Origin')。

2 个解决方案

#1


0  

This issue can be resolved by making the following change within the web.config file of our WebAPI : Reference URL:enabling cross-origin resource sharing on IIS7

通过在WebAPI的web.config文件中进行以下更改可以解决此问题:参考URL:在IIS7上启用跨源资源共享

   <system.webServer>
           <httpProtocol>
               <customHeaders>
                   <add name="Access-Control-Allow-Origin" value="*" />
               </customHeaders>
           </httpProtocol>
       </system.webServer>

#2


0  

I recently aked a question in which I received a detailed info about CORS issues in Spring, read Nikolay answer : Angular JS and Spring MVC @RestController - POST status 0

我最近提出了一个问题,其中我收到了有关Spring中CORS问题的详细信息,请阅读Nikolay回答:Angular JS和Spring MVC @RestController - POST状态0

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2015/10/29/912ec521e67ac57ced887b8e2fb81442.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告