混合内容问题-不安全的XMLHttpRequest端点 [英] Mixed content issue - insecure XMLHttpRequest endpoint

查看:171
本文介绍了混合内容问题-不安全的XMLHttpRequest端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTTPS中浏览网站时,我遇到了混合内容问题. 我从jQuery调用API,但我没有提及该协议,因此假设浏览器应选择与浏览站点相同的协议(http或https). 我的jquery代码如下所示:

I am facing Mixed content issue when i browse my site in HTTPS. I am calling API from jQuery, and I haven't mentioned the protocol, so assuming browser should pick the same protocol with site browsed (http or https). My jquery code looks like below:

$.get("/api/Product/GetMore", { pageIndex: currentPage })
    .done(function(result) {
    .....

当浏览http中的站点并执行所需的操作以获取结果时,它工作正常(能够从API调用中获取结果). 但是,当我浏览该站点并尝试在https中获取结果时,我在浏览器控制台中遇到以下错误.即使我使用https协议对完整的API网址进行硬编码,也会发生同样的事情. 混合内容:"https:///product"上的页面已通过HTTPS加载,但请求了不安全的XMLHttpRequest端点"http:///api/product/getmore?pageIndex = 1".该请求已被阻止;内容必须通过HTTPS提供.

It works fine (able to get the result from API call) when browsed the site in http and do the required action to get the result. But when I browsed the site and try to get the result in https, i am getting below error in browser console. Same thing happens even if i hard-code the complete API url with https protocol. Mixed Content: The page at 'https:///product' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http:///api/product/getmore?pageIndex=1'. This request has been blocked; the content must be served over HTTPS.

XHR加载失败:GET"https:///api/Product/GetMore?pageIndex = 1".

XHR failed loading: GET "https:///api/Product/GetMore?pageIndex=1".

如果您有任何解决方案,请告诉我.

Please let me know if you have any solution.

谢谢, Sharath

Thanks, Sharath

推荐答案

为了工作,您需要指定index.php,以便它知道它正在调用哪个函数.因为这类似于cUrl调用,所以它需要完整路径.为了让呼叫确定使用哪种协议,您需要在开始时使用双斜杠.所以试试这个:

in order to work you need to specify index.php so it knows which function it is calling. Because this is similar to cUrl call it requires full path. And to let call to decide which protocol it is on, you need double slashes at the beginning. So try this:

$.get("//api/Product/GetMore/index.php", { pageIndex: currentPage })

OR

$.get("//api/Product/GetMore/", { pageIndex: currentPage })

解决了我过去的问题.

这篇关于混合内容问题-不安全的XMLHttpRequest端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆