Answer the question
In order to leave comments, you need to log in
How to get around the 405 Not Allowed error when requesting via cURL?
I'm trying to get the page like this:
function request($url = '', $method = 'GET', array $fields = array())
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_USERAGENT =>
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => ($method == 'POST'),
CURLOPT_POSTFIELDS => $fields,
CURLOPT_URL => $url,
CURLOPT_REFERER => $url,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_COOKIEJAR => dirname(__file__) . '/cookie.txt',
CURLOPT_COOKIEFILE => dirname(__file__) . '/cookie.txt',
));
$header['errno'] = curl_errno($ch);
$header['errmsg'] = curl_error($ch);
$header['header'] = curl_getinfo($ch);
$header['content'] = curl_exec($ch);
echo '<pre>';
print_r($header);
echo '</pre>';
exit();
curl_close($ch);
return $header['content'];
}
request('http://www.segodnya.ua/politics/pnews/rada-provalila-golosovanie-za-zakonoproekt-o-speckonfiskacii-neobosnovannyh-aktivov-777709.html'); // 405 Not Allowed
http://www.segodnya.ua/politics.html
http://www.segodnya.ua/politics/p2.html
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question