问题描述
我的网站托管在一个云运行的应用程序上:https://ap4-xxxxxxxx.a.run.app/。 该网站正在调用托管在https://ap4-xxxxxxxx.a.run.app/api/undefined处的API。 但是该请求已在我的浏览器中被阻止。
错误消息:
混合内容:“ https://ap4-xxxxxxxx.a.run.app/”上的页面为 通过HTTPS加载,但请求了不安全的XMLHttpRequest端点 'http://ap4-xxxxxxxx.a.run.app/api/undefined/'。此请求已 封锁内容必须通过HTTPS提供。
API https://ap4-xxxxxxxx.a.run.app/api/undefined在我的浏览器或邮递员上都能正常工作。请求它的代码明确提到了https:
const request = https://ap4-xxxxxxxx.a.run.app/api/${variable};
axios.get(request)
.then(result => {
const PlaceList = result.data.map(
station => {
const isFavorite = PlaceId.includes(Place.number);
return { ...Place,isFavorite: isFavorite }
}
);
this.setState({
PlaceList: PlaceList,isLoading: false
})
updateFavPlaceList(PlaceList);
})
我不明白这里出了什么问题。我的应用程式是拨打HTTP通话,而不是https吗?我在此处(Page loaded over HTTPS but requested an insecure XMLHttpRequest endpoint处读到,有些https是自签名的。是云运行吗?
我尝试了Cors,但没有帮助。
任何观察或建议将不胜感激。
解决方法
看来您确实在某个地方在前端发出HTTP://请求,或者确保您的应用程序未发出对http://
的重定向。
.app
域位于浏览器的硬编码HSTS列表中。如果键入任何.app域,则将其请求为https://
。即使使用XHR,也无法在现代浏览器中通过.app
访问http://
域。
所以这是一个快速修复。我强迫后端(烧瓶)生成https url。 使用此处的答案:Flask url_for generating http URL instead of https
2020-08-11 14:43:39.291 ERROR 117828 --- [ task-1] p.home.phe.adapter.smtp.SMTPAdapter : EmailNotification sending failure :Couldn't connect to host,port: 192.168.28.45,25; timeout 5000
可能有更好的方法(可能是强制前端请求https),请随时对此发表评论。