M
M
Mikhail Pakhmutov2021-06-18 15:07:24
PHP
Mikhail Pakhmutov, 2021-06-18 15:07:24

PHP cUrl: Why am I getting a 403 error?

Hello. I'm trying to send a cUrl request from php to reddit. I would like to delete comments by sending a request from the server, to do this, I first deleted the comment manually, and then looked at what was sent to the server
60cc8af3aaa4d042407139.jpeg

. I tried to use the Replay XHR function in the browser and the request gave the code 200
. code 200.

After that, I copied the information exactly into my cUrl request

// Массив POST
$post = array(
    'id' => 't1_id комментария'
);

// Массив заголовков, как в браузере
$header = array(
    'authority' => 'oauth.reddit.com',
    'accept' => '*/*',
    'accept-encoding' => 'gzip, deflate, br',
    'accept-language' => 'en-GB,en;q=0.9',
    'authorization' => 'скопировал в точности',
    'content-length' => 13,
    'content-type' => 'application/x-www-form-urlencoded',
    'origin' => 'https://www.reddit.com',
    'referer' => 'https://www.reddit.com/',
    'sec-ch-ua' => '^\\^Chromium^\\^;v=^\\^90^\\^, ^\\^Opera^\\^;v=^\\^76^\\^, ^\\^;Not',
    'sec-ch-ua-mobile' => '?0',	
    'sec-fetch-dest' => 'empty',
    'sec-fetch-mode' => 'cors',
    'sec-fetch-site' => 'same-site',
    'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.177',
    'x-reddit-loid' => 'скопировал в точности',
    'x-reddit-session' => 'скопировал в точности'
);

// Параметры cUrl запросу я задал такие
curl_setopt(${"chan".$i}, CURLOPT_RETURNTRANSFER, true);
curl_setopt(${"chan".$i}, CURLOPT_HEADER, true);
curl_setopt(${"chan".$i}, CURLOPT_HTTPHEADER, $header);
curl_setopt(${"chan".$i}, CURLOPT_POST, true);
curl_setopt(${"chan".$i}, CURLOPT_POSTFIELDS, http_build_query($post));
curl_setopt(${"chan".$i}, CURLOPT_AUTOREFERER, true);
curl_setopt(${"chan".$i}, CURLOPT_TIMEOUT, 30);
 curl_setopt(${"chan".$i}, CURLOPT_FOLLOWLOCATION,true);


and sent a request to
https://oauth.reddit.com/api/del?redditWebClient=d...
as in the browser

As a result I get a 403 error, what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-06-18
@galaxy

Read the documentation carefully:


CURLOPT_HTTPHEADER An array of HTTP header fields to set, in the format array('Content-type: text/plain', 'Content-length: 100')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question