0

I want to parse an XML document that is on a different site. Everything works fine if I'm downloading it manually as an XML document, but if I want to get the data directly from the URL

$xml = file_get_contents ( "http://www.blueshop.pl/sklepy.aspx");

I get an error

Warning: file_get_contents (http://www.blueshop.pl/sklepy.aspx): failed to open stream: HTTP request failed!

What is the problem here? I understand from the fact that this ASPX page? Other XML documents from external web sites can be read without problems.

user3514052
  • 418
  • 4
  • 18
  • Welcome to stackoverflow! Can it be that your problem can be resolved using the answers described here? http://stackoverflow.com/questions/697472/why-file-get-contents-returns-failed-to-open-stream-http-request-failed – Arend Feb 28 '16 at 14:46
  • Open the URL in a browser and check if it loads and what is its content. It needs a lot of time to answer, maybe you should pass a [stream context](http://php.net/manual/en/ref.stream.php) as the third argument to [`file_get_contents()`](http://php.net/manual/en/function.file-get-contents.php) to configure a bigger timeout. – axiac Feb 28 '16 at 14:54
  • I tried to use curl (updated question). There is ~9MB file with eshop products. In browser loads without problems, just for a long time – user3514052 Feb 28 '16 at 14:57

1 Answers1

0

solved a problem with curl

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.blueshop.pl/sklepy.aspx");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$file = curl_exec($ch);
curl_close($ch);


$xml = simplexml_load_string($file);
foreach ($xml->PRODUCT as $child)
{
        echo $child->NAME."<br/>";

}
user3514052
  • 418
  • 4
  • 18