我正在嘗試使用 keycloack 進行用戶身份驗證,出于某些測驗目的,我需要禁用 SSL 驗證。在郵遞員中,如果我禁用 SSL 證書驗證,則效果很好。但是在我的 react JS 代碼中,即使它被禁用,它也會給我和錯誤(net::ERR_CERT_AUTHORITY_INVALID),如下面的代碼所示。如果以下代碼中缺少任何內容或需要做任何其他事情,請糾正我。
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
var urlencoded = new URLSearchParams();
urlencoded.append("grant_type", "password");
urlencoded.append("client_id", "clientid");
urlencoded.append("username", "username");
urlencoded.append("password", "password");
urlencoded.append("client_secret", "clientsecret");
const httpsAgent = new https.Agent({
rejectUnauthorized: false,
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: urlencoded,
redirect: 'follow',
Agent: httpsAgent
};
fetch("serverurl/realms/realmname/protocol/openid-connect/token", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
錯誤:網路::ERR_CERT_AUTHORITY_INVALID
uj5u.com熱心網友回復:
當我找到解決方法時,
只需在瀏覽器中輸入請求 URL,如果出現信任錯誤,只需單擊“高級”并選擇“不安全”來加載請求,可能需要至少 3 次嘗試才能加載頁面。并通過 react app 嘗試相同的請求,那么它不會給你這樣的 SSL 錯誤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/325597.html
標籤:javascript 反应 ssl 公理 证书
