无法使用XMLHttpRequest()从http站点检索数据到https

时间:2022-12-04 16:38:35

I have a site hosted on https:// in which I want to pull data from the site which shows the properties of the shares. The URL which returns the data is:

我有一个托管在https://上的网站,其中我想从网站提取数据,显示共享的属性。返回数据的URL是:

http://ir1.euroinvestor.com/asp/ir/xmlirmultiiso2.aspx?companyid=281191

The code which I have developed to get the data is as follows:

我为获取数据而开发的代码如下:

function GetSharesUpdate(){
    // makeing AJAX calls to the web service for getting the share update    
    var xhr = new XMLHttpRequest(); // Set up xhr request
    xhr.open("GET", "http://ir1.euroinvestor.com/asp/ir/xmlirmultiiso2.aspx?companyid=281191", true);   // Open the request
    xhr.responseType = "";   // Set the type of response expected    
    xhr.send();
    //  Asynchronously wait for the data to return
    xhr.onreadystatechange = function () {
        if (xhr.readyState == xhr.DONE) {
            var tempoutput = xhr.responseXML;
            alert(tempoutput);
        }
    }
    //  Report errors if they happen
    xhr.addEventListener("error", function (e) {
        console.error("Error: " + e + " Could not load url.");
    }, false);       
}

I am getting the error on the statement xhr.send(); which is as below:

我在语句xhr.send()上得到错误;如下:

Mixed Content: The page at 'https://[SiteUrl]' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://ir1.euroinvestor.com/asp/ir/xmlirmultiiso2.aspx?companyid=281191'. This request has been blocked; the content must be served over HTTPS.

混合内容:'https:// [SiteUrl]'页面是通过HTTPS加载的,但是请求了一个不安全的XMLHttpRequest端点'http://ir1.euroinvestor.com/asp/ir/xmlirmultiiso2.aspx?companyid=281191'。此请求已被阻止;内容必须通过HTTPS提供。

If I change the URL to https i.e.

如果我将URL更改为https即

https://ir1.euroinvestor.com/asp/ir/xmlirmultiiso2.aspx?companyid=281191

then xhr.send(); is executed without any error but I am getting xhr.responseXML null.

然后是xhr.send();执行没有任何错误,但我得到xhr.responseXML null。

What should I make changes in my code to make it working?

我应该如何更改代码以使其正常工作?

1 个解决方案

#1


0  

The first problem is you are doing ajax request to non-https domain but your domain has SSL installed.

第一个问题是您正在向非https域执行ajax请求,但您的域已安装SSL。

The second problem is Cross origin request CORS, you will have this problem even you solve first (ie. even you try ajax request from non-http domain).

第二个问题是Cross origin请求CORS,即使你先解决了你也会遇到这个问题(即使你从非http域尝试ajax请求)。

Since you are requesting data from another website this is most likely to happen unless the requested server is configured to serve requests for you domain To solve this you need to call the data from your server(proxy server) or have the requested server configured to allow requests from your domain.

由于您要从其他网站请求数据,除非请求的服务器配置为为您的域提供请求,否则最有可能发生这种情况要解决此问题,您需要从服务器(代理服务器)调用数据或将请求的服务器配置为允许来自您域名的请求。

See more - https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

查看更多 - https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

#1


0  

The first problem is you are doing ajax request to non-https domain but your domain has SSL installed.

第一个问题是您正在向非https域执行ajax请求,但您的域已安装SSL。

The second problem is Cross origin request CORS, you will have this problem even you solve first (ie. even you try ajax request from non-http domain).

第二个问题是Cross origin请求CORS,即使你先解决了你也会遇到这个问题(即使你从非http域尝试ajax请求)。

Since you are requesting data from another website this is most likely to happen unless the requested server is configured to serve requests for you domain To solve this you need to call the data from your server(proxy server) or have the requested server configured to allow requests from your domain.

由于您要从其他网站请求数据,除非请求的服务器配置为为您的域提供请求,否则最有可能发生这种情况要解决此问题,您需要从服务器(代理服务器)调用数据或将请求的服务器配置为允许来自您域名的请求。

See more - https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

查看更多 - https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS