0

I'm currently trying to host my website on my University's server and it's served as https when I access it however the RSS content within my website doesn't show when being hosted on the University server because the referencing RSS feeds which use http.

The error I'm currently getting is the following:

Mixed Content: The page at '<uni website address>' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://rss2json.com/api.json?rss_url=http%3A%2F%2Ffeeds.feedburner.com%2Fdaily-express-news-showbiz'. This request has been blocked; the content must be served over HTTPS.

Is there any way I can get the http content to work on the https website?

I'm unable to change any server settings just in case anyone suggests that as a solution.

I've also checked this question a similar question which didn't help me with my issue: Dealing with HTTP content in HTTPS pages

The reason the accepted answer didn't help me was because I didn't know how to rewrite the URL like they suggested or where to include the creation of a proxy page / servlet (and how to create them).

An example of one of the http URL's I'm using is

http://rss2json.com/api.json?rss_url=http%3A%2F%2Ffeeds.bbci.co.uk%2Fnews%2Fworld%2Frss.xml

Community
  • 1
  • 1
Mark O'Sullivan
  • 10,138
  • 6
  • 39
  • 60
  • There is (hopefully) no way around you doing the requests in https. If the rss feed is only offered by http, then you need some agent in between as connector. Typically that is some sort of proxy. All http servers can do such, but obviously we cannot say what your server offers and what permissions you have. You should ask the servers administrator what options you have for this. – arkascha Dec 10 '15 at 20:34

1 Answers1

0

So I eventually got this working by creating a PHP script which I think acted as a proxy so I could receive the feeds I wanted to display. Here's an example of one of the php scripts I created.

bbc_home.php

<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-Type: text/xml");
?>
<?php
function get_url_contents($url){
  $crl = curl_init();
  $timeout = 5;
  curl_setopt ($crl, CURLOPT_URL,$url);
  curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
  $ret = curl_exec($crl);
  curl_close($crl);
  return $ret;
}
$url = "http://rss2json.com/api.json?rss_url=http%3A%2F%2Ffeeds.bbci.co.uk%2Fnews%2Fworld%2Frss.xml";
$str = file_get_contents($url);
echo $str;
?>

Snippet of my JS file

function bbcHomeNews() {
   var xhr = new XMLHttpRequest();
   xhr.onreadystatechange = function(){
           if (xhr.readyState==4 && xhr.status==200)
           {
               var data = JSON.parse(xhr.responseText);
               if(data.status == 'ok'){
                   var dataItemLength = data.items.length;
                   itemAmount = 4;
                   for(var i=0;i<itemAmount;++i){
                        $("#newsFeedContent").append("<div class='panel' id='bbcNewsContent'>" +
                        "<h2>" + data.items[i].title + "</h2>" +
                          "<div>" + data.items[i].description + "</div>" +
                          "<br>" +
                          "<button class='btn btn-default'><a href=" + data.items[i].link + ">More</a></button>" +
                        "</div>");
                      }
               }
               if(data.status == 'error'){
                 returnErrorMessage("BBC Feed");
               }
           }
       };
   xhr.open('GET','scripts/php/bbc_home.php',true);
   xhr.send();
}

I hope this helps anyone who has been stuck with a similar issue!

Mark O'Sullivan
  • 10,138
  • 6
  • 39
  • 60