【问题标题】:SSL/TSL Certificate for IP AddressIP 地址的 SSL/TLS 证书
【发布时间】:2020-09-28 06:53:52
【问题描述】:

我有以下 curl 命令来授予用户(本地)权限:

curl "https://10.10.135.35/9880/grant_permission?user=username&role=role" -k

我想在 js 中使用 fetch 来达到同样的目的。比如:

const fetchAPIPro = (username, role) =>
    fetch(`https://10.10.135.35/9880/grant_permission?user=${username}&role=${role}`, {
      referrerPolicy: 'unsafe-url',
      credentials: 'omit',
    })
      .then((response) => {
        if (!response.ok) {
          throw new Error('Network response was not ok');
        }
        return response.blob();
      })
      .then((response) => response.json())
      .then((data) => console.log(data))
      .catch((error) => {
        console.error('There has been a problem with your fetch operation:', error);
      });

它返回了NET::ERR_CERT_INVALID。我认为这是因为我创建了 SSL/TSL 认证(自签名)。 有没有办法绕过fetch 或授予域认证?

【问题讨论】:

标签: javascript reactjs ssl ssl-certificate


【解决方案1】:

您需要在标题中添加rejectUnauthorized: false

【讨论】:

    【解决方案2】:

    如果您在浏览器中执行,则会引发该错误,因为浏览器不会针对跨域域的自签名证书进行验证。您可以从letsencrypt获得免费的有效证书

    【讨论】:

    • 让我们使用 CertBot 加密只允许域 SSL 而不是 IP 地址 SSL
    猜你喜欢
    • 2021-01-03
    • 2020-09-28
    • 2022-07-06
    • 2015-11-25
    • 1970-01-01
    • 2023-03-24
    • 2013-08-01
    • 2014-09-14
    • 2010-11-08
    相关资源
    最近更新 更多