为什么Axios不使用相同的协议

时间:2018-09-14 15:59:22

标签: ajax axios

我遇到了错误:

Mixed Content: The page at 'https://mywebsite.io/content_library' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://mywebsite.io/api/blog_posts/'. This request has been blocked; the content must be served over HTTPS.

在我的axios请求中,我只是使用相对网址'/ api / blog_posts /`,所以axios为什么不使用https而不是http发送请求?

1 个答案:

答案 0 :(得分:0)

我遇到了同样的错误,我的网站通过https提供了haproxy,而nginx服务器仅运行http 我不认为它的axios是相关的,而是XmlHttpRequest的一个普遍问题?

但是,我已经设置了:Content-Security-Policy来升级不安全的请求,至少可以在chrome上解决此问题。但是我认为Microsoft Edge不支持此功能。

因此,更好的解决方法应该是在带有https的axios中使用absoluteURL。

我还是不明白,为什么axios / browser在这里使用http ...