简体   繁体   中英

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. 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"

I have tried making the request using the xhr object and using jquery but i keep getting the same mistake

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

  });

I would like to be able to send the POST request from the POS to the payment terminal.

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. 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."

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 .

After i applied this changes i was able to make the succesful requests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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