MrViK xD MrViK xD - 3 months ago 23
HTTP Question

How can I load HTTP from HTTPS

I'm using HTTPS in my server, but I have a second server with some information and I want to take some files from there. I'm now using the code below:

$.get("http://myserver.com/uno.html", function(data, status){
if (dat == "ok") {
alert("Myserver.com is online");
}
}).fail(function(e) {
alert("Myserver.com is offline");
});


With that code, Chrome is throwing the exception


"https://otherserver.com" was loaded from https but requested an insecure XMLHttpRequest "http://myserver.com/uno.html". Request has been blocked; The content must be server over https.


The question now is how can I load any HTTP request to make Chrome think the request was served over HTTPS? Keep in mind that the only HTTPS server is otherserver.com and I can't implement HTTPS in "myserver.com"
This question is not repeated because all the servers are mine and I have full control on the "Same origin policies"

Answer

You can do request to otherserver.com and then from server-side do request to myserver.com and return results. For example (example in PHP, but it depends on your backend):

//request.php
echo file_get_contents("http://myserver.com/uno.html");

Then on client-side:

$.get("https://otherserver.com/request.php", function(data, status){
    if (dat == "ok") {
        alert("Myserver.com is online");
    }
}).fail(function(e) {
    alert("Myserver.com is offline");
});