Tag: Cors

$ http请求不会在angular度CORS中跨域发送cookie

首先我想告诉我已经阅读了Stack的所有问题以及与CORS相关的所有问题,但是实现仍然不起作用。 我的APPbuild立在angular度粗暴的演示之上: 所以我有在应用程序configuration: $httpProvider.defaults.useXDomain = true; $httpProvider.defaults.withCredentials = true; delete $httpProvider.defaults.headers.common['X-Requested-With']; 我知道他们正确设置(debugging)。 在我的“安全”应用程序中,我正在为当前用户请求跨域: return $http.get(LAYOUT_CONFIG.baseURL + '/current-user').then(function(response) { //service.currentUser = response.data.user; service.currentUser = response.data; return service.currentUser; }); 我在第一个请求中获得这些标头: Access-Control-Allow-Credentials:true Access-Control-Allow-Headers:accept, origin, content-type, cookie Access-Control-Allow-Methods:GET,POST Access-Control-Allow-Origin:http://admin.vibetrace.com Access-Control-Max-Age:1728000 Connection:keep-alive Content-Encoding:gzip Content-Type:text/html; charset=utf-8 Date:Sun, 02 Jun 2013 11:07:49 GMT P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi […]

Rails在CORS预检选项请求中响应404

我使用Rails 4创build了一组服务,我正在使用JavaScript浏览器应用程序。 交叉原点GETS工作正常,但我的POST失败了预检选项检查404错误。 至less,我想这就是发生了什么事情。 这些错误出现在控制台中。 这是Mac上的Chrome 31.0.1650.63。 OPTIONS http://localhost:3000/confessor_requests 404 (Not Found) jquery-1.10.2.js:8706 OPTIONS http://localhost:3000/confessor_requests No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. jquery-1.10.2.js:8706 XMLHttpRequest cannot load http://localhost:3000/confessor_requests. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. main.html:1 我已经search了高和低的指示启用CORS,我很难过。 通常的build议似乎是把这样的东西放在应用程序控制器,我做了。 […]

跨域资源共享GET:“拒绝从响应中获取不安全标题”etag“'

一个简单的GET请求,没有自定义标题。 响应按预期返回。 正文中的数据是可访问的,但不是标题。 当我尝试访问“etag”标题时,浏览器引发exception: 拒绝获取不安全的标题“etag” Chrome,Safari和Firefox的行为都是一样的。 我没有在IE上testing它。 我在这里错过了什么?

为什么需要Access-Control-Expose-Headers?

我正在寻找具体的安全原因,为什么join。 这是一个WTH的时刻,当我正在实施cors,并可以看到所有的标题被返回,但我不能通过JavaScript访问它们..

如何正确使用AngularJS中的HTTP.GET? 具体而言,对于外部API调用?

我在controller.js中有以下代码, var myApp = angular.module('myApp',[]); myApp.service('dataService', function($http) { delete $http.defaults.headers.common['X-Requested-With']; this.getData = function() { $http({ method: 'GET', url: 'https://www.example.com/api/v1/page', params: 'limit=10, sort_by=created:desc', headers: {'Authorization': 'Token token=xxxxYYYYZzzz'} }).success(function(data){ return data }).error(function(){ alert("error"); }); } }); myApp.controller('AngularJSCtrl', function($scope, dataService) { $scope.data = dataService.getData(); }); 但是,我想我可能犯了与CORS有关的问题。 你能指点一下正确的方式来打这个电话吗? 非常感谢!

AngularJS CORS问题

我已经search了超过200个网站(可能夸大,但不是太多),如何能够与angularjs处理cors。 我们有一台运行Web API服务器的本地机器。 我们正在开发一个调用API数据的客户端。 从服务器运行客户端时,我们收到的数据没有问题。 当我们从一个不同的域运行它时,我们在获取数据和空白响应时会得到一个红色的200响应。 这里是一些代码: var myApp = angular.module('Project', ['ngResource']); myApp.config(function($routeProvider){ $routeProvider. when('/new', {templateUrl:'templates/new.html', controller:'EditProjectController'}). when('/mobile', {templateUrl:'templates/mobile.html', controller:'ProjectController'}). when('/it', {templateUrl:'templates/it.html', controller:'ProjectController'}). when('/writing', {templateUrl:'templates/writing.html', controller:'ProjectController'}). when('/all', { templateUrl: 'templates/all.html' }). when('/login', { templateUrl: 'partials/_login.html' }). otherwise({ redirectTo: '/all' }); }); myApp.config(['$httpProvider', function ($httpProvider) { $httpProvider.defaults.useXDomain = true; delete $httpProvider.defaults.headers.common['X-Requested-With']; } ]); myApp.controller('ProjectController', function myApp($scope, […]

为什么经过身份validation的CORS请求的预检选项请求在Chrome中运行,而不是在Firefox中运行?

我正在编写一个JavaScript客户端以包含在第三方网站上(请考虑Facebook Likebutton)。 它需要从需要基本HTTPauthentication的API中检索信息。 简化的设置如下所示: 第三方网站在其页面上包含此片段: <script async="true" id="web-dev-widget" data-public-key="pUbl1c_ap1k3y" src="http://web.dev/widget.js"> </script> widget.js调用API: var el = document.getElementById('web-dev-widget'), user = 'token', pass = el.getAttribute('data-public-key'), url = 'https://api.dev/', httpRequest = new XMLHttpRequest(), handler = function() { if (httpRequest.readyState === 4) { if (httpRequest.status === 200) { console.log(httpRequest.responseText); } else { console.log('There was a problem with the request.', httpRequest); […]

Access-Control-Allow-Origin不允许$ http.get,但$ .ajax是

从我控制的远程服务器获取json时遇到问题。 我有2个Web应用程序,一个正在服务数据并在端口3311上运行,另一个正在请求数据,正在端口5000上运行。 使用jquery的以下工作: $.ajax({ url: "http://localhost:3311/get-data", type: 'GET', dataType: 'json', beforeSend: function(xhr) { xhr.setRequestHeader("x-some-header", "some-value"); } }) .done(function(data) { $rootScope.$apply(function() {d.resolve(data); }); }) .fail(function(data) { $rootScope.$apply(function() {d.reject(data); }); }); 当试图与angular度相同的获取请求 $http .get("http://localhost:3311/get-data", { headers: {"x-some-header": "some-value"} }) .success(function(data) { d.resolve(data);}) .error(function(data) { d.reject(data); }); 我收到错误 Origin http://localhost:5000 is not allowed by Access-Control-Allow-Origin. 控制台日志显示在OPTIONS请求返回HTTP200之后发生错误 OPTIONS http://localhost:3311//get-data […]

在任何低于10的IE版本中,XMLHttpRequest访问被AngularJS拒绝

在任何10以前版本的Microsoft IE浏览器上查看我的应用程序时,在控制台中出现以下奇怪的错误: 我已经尝试在AngularJS库之前添加以下JavaScript代码来取消控制台: console.log = function(){}; window.console = {log: function(){}}; 这没有什么区别。 在IE 10中出现同样的错误: SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied. 可能我试图从API获取“/我”,以检查用户是否通过身份validation或访客。 基本上。 消除那些恼人的控制台错误,每次服务器给出的响应以外的2XX或3XX将是伟大的! 更新:这似乎与通过不同的子域(CORS)访问API有关;

CORS请求 – 为什么cookies没有发送?

我有一个跨域AJAX GET获得预先成功,但cookies不附加到GET请求。 当用户点击一个loginbutton时,一个POST被logging下来,这个用户可以跨域正确的工作。 JavaScript是: $.ajax(signin_url, { type: "POST", contentType: "application/json; charset=utf-8", data: JSON.stringify(credentials), success: function(data, status, xhr) { signInSuccess(); }, error: function(xhr, status, error) { signInFailure(); }, beforeSend: function(xhr) { xhr.withCredentials = true } }); 响应标题包括一个cookie: Set-Cookie:user_token=snippysnipsnip; path=/; expires=Wed, 14-Jan-2032 16:16:49 GMT 如果login成功,将获取JavaScript GET请求以获取当前用户的详细信息: function signInSuccess() { $.ajax(current_user_url, { type: "GET", contentType: "application/json; charset=utf-8", success: […]