简体   繁体   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?

I need to make a POST request from a POS(point of sale)(http) to a payment terminal(https), they are connected in my local network. 我需要从POS(销售点)(http)向支付终端(https)发出POST请求,它们已连接到我的本地网络。 When i make the request from Postman everything works correctly but whenever i make a request from the POS i get error "POST https://myIPaddress:8443/nexo/ net::ERR_CERT_AUTHORITY_INVALID" 当我从邮递员发出请求时,一切正常,但是每当我从POS发出请求时,都会收到错误消息“ POST https:// myIPaddress:8443 / nexo / net :: ERR_CERT_AUTHORITY_INVALID”

I have tried making the request using the xhr object and using jquery but i keep getting the same mistake 我尝试使用xhr对象和jquery发出请求,但我一直遇到相同的错误

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 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);

  });

I would like to be able to send the POST request from the POS to the payment terminal. 我希望能够将POST请求从POS发送到付款终端。

After some research the issue turned out to be related to the browser not allowing requests to localhost over HTTPS when an invalid certificate was presented. 经过一番研究后,发现该问题与浏览器有关,当提供了无效证书时,该浏览器不允许通过HTTPS向本地主机发出请求。 In order to allow these requests with these characteristics in chrome, one must go to chrome://flags/ and enable the option "Allow invalid certificates for resources loaded from localhost." 为了在chrome中允许具有这些特征的这些请求,必须转到chrome:// flags /并启用选项“允许对从本地主机加载的资源使用无效的证书”。

In the case of firefox its similar, one must allow Self-Signed Certificates on Localhost, there is an excellent article on how to solve this issue here . 在Firefox其相似的情况下,必须允许在本地主机上自签名证书,对如何解决这个问题一个很好的文章在这里

After i applied this changes i was able to make the succesful requests. 应用此更改后,我可以发出成功的请求。

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

相关问题 如何从 HTTPS 网站发出 HTTP 请求? - How can I make an HTTP request from an HTTPS website? 如果发生错误,如何更改http发布请求的网址 - How can i change the url of a http post request if there is an error 如何让浏览器在发起跨域 HTTP 请求时包含主机源域的 cookie - How to make the Browser include the cookies of the domain of the host origin when making a cross-origin HTTP request 如何从使用 HTTP 而不是 HTTPS 发送的安全网站进行重定向 - How can I make redirects from my secure website sent with HTTP instead of HTTPS 如何使用修改的User-Agent标头javascript或php进行跨源Http发布请求? - How to make a cross origin Http post request with modified User-Agent header javascript or php? 如何使用来自本地存储的令牌发出发布请求 - How do i make a post request with my token coming from local storage 如何使我的PHP API将JSON返回到Javascript HTTP POST / GET请求? - How do I make my PHP API return JSON to a Javascript HTTP POST/GET request? 如何制作jQuery http-> https AJAX请求 - How to make a jQuery http -> https AJAX request 如何使用 Axios 向 API 发出 https 请求? - How can I make a https request to Stripe API with Axios? 如何将 javascript 文件创建为有效的 https url? - How can I make a javascript file to a valid https url?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM