Answer the question
In order to leave comments, you need to log in
How to log in using CURL on a site with ASP.NET?
Good afternoon! I already asked two questions on the same case, received an answer to them and thought that I could handle it myself, but it wasn’t there, I still run into some dead ends. Please help again)
In general, you need to parse data from the auto parts site . There is a search for several articles at once, but it is available only after authorization. I'm trying to write a PHP script that will log in to this site and, in fact, look for the necessary spare parts there and parse them.
The usual functionality of Simple HTML DOM for this, of course, is not enough. I realized that I need to use cURL, and wrote the following code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://parts.major-auto.ru/SearchNew/ByList');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, 'ASP.NET_SessionId=abcdefghij12345677890...; .ASPXAUTH=DSFHJSDFDSG6785DFG78DF6G78DF6G7896D8F9G7D...');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'searchElements' => $data,
'SearchByList' => 'Поиск',
]);
$html = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://parts.major-auto.ru/Account/LogOn');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'UserName' => '+7(123)456-78-90',
'Password' => 'password',
'btnLogOn' => 'Вход',
]);
$html = curl_exec($ch);
echo 'HTTP код ответа сервера: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE) . '<br>';
curl_close($ch);
Answer the question
In order to leave comments, you need to log in
In Firefox/Chrome, you can get requests in the curl format: web development > network > right-click on the request and select copy > copy as curl. well, based on these data, we form a curl request in php
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question