【发布时间】:2016-08-19 14:23:25
【问题描述】:
我其实不明白这个问题。我不太喜欢 SSL 和证书。
test.kanubox.de 上的一个脚本(您可以在那里尝试并查看源代码)使用 ajax 调用 sandbox.api.kehrwasser.com/kanubox/v1 上的 rest 服务器。显然 CORS 是必需的,并且在没有 SSL 的情况下运行良好,因此我假设 CORS 设置正确。对 API 的 OPTIONS 请求(预检)的标头数据确认
Access-Control-Allow-Origin: *
Upgrade: h2,h2c
Pragma: no-cache
Keep-Alive: timeout=5, max=100
Content-Type: application/json
Content-Encoding: gzip
Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT
Server: Apache/2.4
Expires: Fri, 19 Aug 2016 12:15:58 GMT
Access-Control-Max-Age: 500
Access-Control-Allow-Headers: x-requested-with, Content-Type, origin, authorization, accept, client-security-token, Access-Control-Allow-Origin, X-Frame-Options
但是当我切换到 https://test.kanubox.de 并在 https://sandbox.api.kehrwasser.com/kanubox/v1 调用 API 时,我从 FireFox 收到 CORS 错误,例如“(跨源被阻止)
Reason: CORS-Header 'Access-Control-Allow-Origin' missing
(翻译错误信息)
证书来自我的托管商并由我的托管商自己验证。我不确定,但那是“自签名”吗?那么也许 FF 阻止它是因为它不信任它?
这是我的代码:
var test = angular.module("test", []);
test.constant('apiConfig', {
apiUrl: "https://sandbox.api.kehrwasser.com/kanubox/v1"
});
test.controller("TestController", function($scope, $http, apiConfig) {
var credentials = { mail: "user@mailserver.com", password: "12345" };
// POST REQUEST VIA SSL
$http({
url: apiConfig.apiUrl + "/users/auth/",
method: 'POST',
data: credentials
}).success(function(data, status, headers, config) {
$scope.variable = data;
}).error(function(data, status, headers, config) {
$scope.variable = data;
});
});
【问题讨论】:
-
所有感兴趣的人:问题出在 Firefox 内部。一个特定的版本有这个问题。在早期或更高版本以及其他浏览器中,没有问题。我只是问了用户在这个特定的浏览器版本中更新浏览器。
标签: javascript angularjs ajax ssl xmlhttprequest