gpt4 book ai didi

javascript - Ajax Angular SSL CORS

转载 作者:行者123 更新时间:2023-11-29 21:16:51 26 4
gpt4 key购买 nike

这个问题我其实不太明白。我不太喜欢 SSL 和证书。

test.kanubox.de 上的脚本(您可以在那里尝试并查看源代码)使用 ajax 调用 sandbox.api.kehrwasser.com/kanubox/v1 上的 rest 服务器。显然,CORS 是必需的,并且在没有 SSL 的情况下也能正常工作,因此我假设 CORS 设置正确。 API 的 OPTIONS 请求(预检)中的 header 数据确认

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

(翻译的错误信息)

证书来 self 的托管商并由我的托管商自己验证。我不确定,但它是“自签名”吗?所以也许 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;

});

});

最佳答案

如果我浏览到 https://test.kanubox.de/ ,那么服务器证书在我的 firefox 浏览器中是未知的。它确实是一个自签名证书,由“Hostpoint DV SSL CA - G2”本身颁发!

要使该 SSL 证书有效,您需要浏览器中的“Hostpoint”根证书。这正是你让它发挥作用的方式!所以,这是一个受信任的 ROOT 证书问题。

当SSL问题解决后,再看CORS问题。

https://sandbox.api.kehrwasser.com/kanubox/v1/中使用的证书是由著名的 CA“Let's incrypt”发布的。这很好用。

关于javascript - Ajax Angular SSL CORS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39041433/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com