A
A
Artyom Peshkov2016-06-16 20:02:42
PHP
Artyom Peshkov, 2016-06-16 20:02:42

RSS - opens without problems in the browser, but does not load through PHP in any way. Why?

Good afternoon Toaster!
I've already broken my head, honestly. I have already encountered problems with accessing sites through PHP, but this has always been solved, but this time it didn’t. I am turning to you for help.
This address quite calmly comes off in the browser, giving RSS:
zakupki.gov.ru/epz/order/quicksearch/rss?searchStr...
But neither through file_get_contents(), nor through cURL, with a variety of combinations of settings, I can get it I can not.
file_get_contents example:

$context = stream_context_create(array(
  'http' => array(
    'method' => 'GET',
    'protocol_version' => '1.1',
    'header' => array(
      'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0',
    )
  )
));
$r = file_get_contents($url, false, $context); 
debug($r);
debug($http_response_header);

Returns bool false and a "500 Internal Server Error" error.
An example of cURL parameters (tried in different ways):
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_REFERER, 'http://zakupki.gov.ru/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE); 
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0');
curl_setopt($ch, CURLOPT_URL, $o['url']);

This one thinks for about half a minute and generally gives out a page that says "Error establishing a connection to the database."
I'm confused. Download this RSS is very necessary. I hope for your help.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey, 2016-06-16
@Gorky

Your first example with file_get_contents worked fine.
Probably a lot of requests were made, added to the ban or cached on the proxy?

A
Alexey, 2016-06-16
@alsopub

It worked for me like this:

$url = "http://zakupki.gov.ru/epz/order/quicksearch/rss?searchString=&morphology=on&pageNumber=1&sortDirection=false&recordsPerPage=_10&showLotsInfoHidden=false&fz44=on&fz223=on&af=on&regions=&priceFrom=0&priceTo=200000000000&currencyId=1&publishDateFrom=16.06.2016&publishDateTo=16.06.2016&updateDateFrom=&updateDateTo=&sortBy=PRICE";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:47.0) Gecko/20100101 Firefox/47.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_HEADER, 0);
$exec=curl_exec ($ch);
echo($exec);

I
Immortal_pony, 2016-06-16
@Immortal_pony

This code is working (I checked it myself). Result: prntscr.com/bh7uvu

$context = stream_context_create(array(
  'http' => array(
    'method' => 'GET',
    'protocol_version' => '1.1',
    'header' => array(
      'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0',
    )
  )
));
$r = file_get_contents($url, false, $context); 
var_dump($r);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question