[英]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.