gpt4 book ai didi

javascript - 通过从 XMLHTTPREQUEST 调用将 Windows 服务中的自托管 Web Api 配置为使用 SSL

转载 作者:太空宇宙 更新时间:2023-11-03 14:43:25 25 4
gpt4 key购买 nike

我已经通过从 XMLHTTPREQUEST(html 页面)调用它来使用 SSL 在 Windows 服务中配置了自托管 Web API。

我正在使用 CERTENROLLLib.dll 在代码中创建自签名 SSL 证书。

证书正在创建,并且正在添加到浏览器的受信任的根证书颁发机构(在浏览器的 SSL 证书列表中)。

而且我还使用了 CORS,http/https 在 IE 中工作正常。

只有 Http 在 chrome 中唤醒,但 https 在 chrome 中不起作用 - 直接进入错误(功能)并显示警告消息。

我不知道问题出在哪里 - 它在网络 API 或 html 页面中。这是我的 html 函数。

function COMPortOpen() {
var url = "https://localhost:8989/Values/COMPortOpen";
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if (xmlhttp.responseText == '"0"') {
alert("Device successfully connected");
}
else {
alert("Device not connected");
}
}
xmlhttp.onerror = function () {
alert("Check If Service/Utility is Running");
}
}
xmlhttp.open("POST", url, true);
xmlhttp.withCredentials = true;
xmlhttp.send();
}

我错过了什么?如何让 Chrome 浏览器使用 SSL 证书。

最佳答案

您是否尝试过在 Chrome 浏览器中允许 CORS?

对于 Windows,从命令行在 chrome 目录中运行它(关闭所有正在运行的 chrome 实例后):

chrome.exe --disable-web-security

或者,您可能想为 chrome 安装一个插件,以打开/关闭 CORS。

关于javascript - 通过从 XMLHTTPREQUEST 调用将 Windows 服务中的自托管 Web Api 配置为使用 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41237581/

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