Php curl script to get aspx page content

Hi guys, the first time on the forum, so scream if I don't know it right.

I tried about a day to get the XML file in my application. This is usually not a problem, and I have two other channels that enter the application using the simpleXml method that I provided below.

My problem is that this other page is an aspx page and seems to have some kind of redirect or maybe just use the aspx framework that uses a clean url.

This is the script I used for two other data streams that work fine.

$grb_feed_url = 'http://www.grb.uk.com/rss.php'; $grb_jobs = simplexml_load_file($grb_feed_url, 'SimpleXMLElement', LIBXML_NOCDATA); 

This is great, but when I try it for the URL http://www.milkround.com/rss.aspx , it returns nothing.

Then I tried the cURL script, this file is great for the godaddy example, but returns nothing for the Milkround URL. It’s also strange that if I delete the line CURLOPT_FOLLOWLOCATION or set it to 0, it will return with a “moved object”.

 function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $data = curl_exec($ch); curl_close($ch); return $data; } $returned_content = get_data('http://www.milkround.com/rss'); print_r($returned_content); /* example of a url that works using this script */ /* $returned_content = get_data('http://www.godaddy.com/hosting/website-builder.aspx'); */ 

Any help would be really appreciated.

Thanks in advance.

+4
source share
1 answer

You need to include the User-Agent header in the cURL request, otherwise the site will generate error 501:

 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/4"); 
+3
source

Source: https://habr.com/ru/post/1401580/


All Articles