F
F
freeeeez2021-11-01 11:00:45
PHP
freeeeez, 2021-11-01 11:00:45

Why cookies stop working in the parser or how to change it to work?

There is a site on ASP.NET with an authorization system, you need to receive information as an authorized user. When authorizing in the browser, cookies and a session id are assigned. I throw them on the site with a regular CURL request and everything works exactly 24 hours a day! Then again I authorize in the browser, substitute a new cookie and again it works for a day. And so it goes on for 3-5 days, and then everything so that I don’t make cookies from the browser ceases to fit, although I do everything the same and the request returns the answer:

<h2>401 - Unauthorized: Access is denied due to invalid credentials.</h2>\r\n
<h3>You do not have permission to view this directory or page using the credentials that you supplied.</h3>


A week later, somewhere, the site again starts to give cookies that are suitable for the Curl request and everything starts working again. Where to dig? Tell me who knows what I'm doing wrong? Maybe there is some feature of ASP.NET in authorization. Or am I reinventing the wheel and there are ways to get the data easier?

Request headers
General
Request URL: https://site.ru/DataItemGet?appid=y8H3Vuv_nOx1vVR&t=1635752192
Request Method: POST
Status Code: 200 OK
Remote Address: 192.168.0.1:443
Referrer Policy: strict-origin-when-cross-origin

Response Headers
Access-Control-Expose-Headers: Request-Context
Cache-Control: private
Content-Encoding: gzip
Content-Type: application/json; charset=utf-8
Date: Mon, 01 Nov 2021 07:35:54 GMT
ntCoent-Length: 561207
Request-Context: appId=cid-v1:699c994c-9aca-4b75-acb9-356556246c7f
Server: Microsoft-IIS/10.0
Transfer-Encoding: chunked
X-Powered-By: ASP.NET

Request Headers
Accept: text/plain, */*; q=0.01
Accept-Encoding: gzip, deflate, br
Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7,lt;q=0.6,de;q=0.5
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 123
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: ai_user=KG2Is|2021-10-29T11:50:12.226Z; .AspNet.Cookies=bz7gK0L7lQf5Y3noooafTvXA5avZHCIKt_bRL-MDBjwQtffO-dONkVtbEI1OcgBTfhp3H4jK0gOzRIRBjH-VOur0N1NOeDYPdItU_FZdbxJIhQqaqg3Pfqcwfsfu4lL7eVdNN9m9W1k_V_L6nqT4g87mLb8YCw4qz4gceBBYz848yrg1SmX7wMMAbsQ9Q_1uzd0TwFgDxwWk_ZqRvak65nmi-WXooy5DrjaqcyK10DIjZwDHamsZXV2ddcQdMR0iGpn1J-b9-A-spe0O_JMTsQLCWS84CkSQaLXjqkhJSpnsGCiWeFVnaBWeyBq88a3-mQwCjtJkQdznrDKlbP8VOneEiMUGwXuWltyVSzo8c3qPG3Fq6u4qkyjNdv8boTVZ; ASP.NET_SessionId=xgsinag3sqrglk35virjq40m
Host: site.ru
Origin: https://site.ru
Pragma: no-cache
Referer: https://site.ru
sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
sec-ch-ua-mobile: ?0
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

Query String Parameters
appid: y8H3Vuv_nOx1vVR
t: 1635752192

Form Data
{"methodName":"ListLot","withParams":true,"fullDataSet":true,"persistParamSet":false}:


CURL script code
$array = array(
  "methodName"=>"ListLot",
  "withParams"=>true,
  "fullDataSet"=>true,
  "persistParamSet"=>false
);        
$curl = curl_init('https://site.ru/DataItemGet');
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($array)); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
'Cookie: ai_user=KG2Is|2021-10-29T11:50:12.226Z; .AspNet.Cookies=bz7gK0L7lQf5Y3noooafTvXA5avZHCIKt_bRL-MDBjwQtffO-dONkVtbEI1OcgBTfhp3H4jK0gOzRIRBjH-VOur0N1NOeDYPdItU_FZdbxJIhQqaqg3Pfqcwfsfu4lL7eVdNN9m9W1k_V_L6nqT4g87mLb8YCw4qz4gceBBYz848yrg1SmX7wMMAbsQ9Q_1uzd0TwFgDxwWk_ZqRvak65nmi-WXooy5DrjaqcyK10DIjZwDHamsZXV2ddcQdMR0iGpn1J-b9-A-spe0O_JMTsQLCWS84CkSQaLXjqkhJSpnsGCiWeFVnaBWeyBq88a3-mQwCjtJkQdznrDKlbP8VOneEiMUGwXuWltyVSzo8c3qPG3Fq6u4qkyjNdv8boTVZ; ASP.NET_SessionId=xgsinag3sqrglk35virjq40m',
));

$response = curl_exec($curl);

$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $headerSize);
$header = headersToArray($header);
$body = substr($response, $headerSize);


$result = json_decode($body);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeeeez, 2021-11-11
@freeeeez

I solved the issue using Headless Chrome, of course I had to get confused, but it was worth it

A
Anton Shamanov, 2021-11-01
@SilenceOfWinter

1. use CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE
2. kikis expire and become invalid incl. it's better to re-login with each session, and then send other requests with the same $curl descriptor

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question