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