我使用以下curl命令向用户(本地)授予权限:
curl "https://10.10.135.35/9880/grant_permission?user=username&role=role" -k我想在js中使用fetch来达到同样的目的。类似于:
const fetchAPIPro = (username, role) =>
fetch(`https://10.10.135.35/9880/grant_permission?user=${username}&role=${role}`, {
referrerPolicy: 'unsafe-url',
credentials: 'omit',
})
.then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.blob();
})
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => {
console.error('There has been a problem with your fetch operation:', error);
});它返回NET::ERR_CERT_INVALID。我认为这是因为我创建了SSL/TSL证书(自签名)。有什么办法可以在fetch中绕过这一点,或者为该域授予认证吗?
发布于 2020-06-09 15:04:44
您需要在标头中添加rejectUnauthorized: false
发布于 2020-06-09 15:06:15
如果你在浏览器中执行,这个错误将被抛出,因为浏览器不会针对跨域的自签名证书进行验证。您可以从letsencrypt获得一个免费的有效证书
https://stackoverflow.com/questions/62276789
复制相似问题