E
E
entermix2016-12-08 20:42:49
Parsing
entermix, 2016-12-08 20:42:49

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

But I get a 405 Not Allowed error
. I manage to get, for example, the following pages:
http://www.segodnya.ua/politics.html
http://www.segodnya.ua/politics/p2.html

But specifically a page with a full description - no.
I tried to pass all the headers, but it did not work out to get the content.
If you send a request using Fiddler - everything is ok. What kind of protection is this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-12-08
@entermix

Remove POST - CURLOPT_POST and CURLOPT_POSTFIELDS.
I see that you corrected something from the previous question.
In general, if you remove both of these options, then everything works.
Further, I think, you will understand.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question