繁体   English   中英

当源为http并且目标URL为https时,如何在本地网络中发出POST请求?

[英]How can i make a POST request in my local network when the origin is http and the target url is https?

我需要从POS(销售点)(http)向支付终端(https)发出POST请求,它们已连接到我的本地网络。 当我从邮递员发出请求时,一切正常,但是每当我从POS发出请求时,都会收到错误消息“ POST https:// myIPaddress:8443 / nexo / net :: ERR_CERT_AUTHORITY_INVALID”

我尝试使用xhr对象和jquery发出请求,但我一直遇到相同的错误

jQuery的

const settings = {
      async: true,
      crossDomain: true,
      url: 'https://myIPAdress:8443/nexo/',
      method: "POST",
      data: JSON.stringify({
        data
      })
    };

    $.ajax(settings).done(function (response) {
      console.log(response);
    });

JS / XHR

var data = JSON.stringify({
      data
    });

    var xhr = new XMLHttpRequest();
    xhr.withCredentials = true;

    xhr.addEventListener("readystatechange", function () {
      if (this.readyState === 4) {
        console.log(this.responseText);
      }
    });

    xhr.open("POST", "https://myIPAdress:8443/nexo");

    xhr.send(data);

  });

我希望能够将POST请求从POS发送到付款终端。

经过一番研究后,发现该问题与浏览器有关,当提供了无效证书时,该浏览器不允许通过HTTPS向本地主机发出请求。 为了在chrome中允许具有这些特征的这些请求,必须转到chrome:// flags /并启用选项“允许对从本地主机加载的资源使用无效的证书”。

在Firefox其相似的情况下,必须允许在本地主机上自签名证书,对如何解决这个问题一个很好的文章在这里

应用此更改后,我可以发出成功的请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM