I
I
Ilya2018-04-30 15:08:20
PHP
Ilya, 2018-04-30 15:08:20

Why doesn't the Guzzle POST request to fill out a third party form work?

The library has a book search form . But initially there is no tag and inputs with the necessary name on the page. The user writes the title of the book and presses the button. As I understand it, after that, a script is triggered that reads the filled data, forms a real form with them and sends it using the POST method. Without reloading the page, the user gets the search result: I need to programmatically fill in this form and display the result page. I analyze using the Network panel what data is being transmitted, I repeat the request with these parameters, but it does not work .<form>
5ae7013230135461721418.png
5ae70160e1bf9353311085.png
5ae7042f6dcbf777505505.png

require 'vendor/autoload.php';

// Подключаем класс Client
use GuzzleHttp\Client;

// Инициализируем класс для работы с удаленными веб-ресурсами
$client = new Client();

// Делаем запрос, получаем ответ
$response = $client->request("POST", "http://opac.rgub.ru/cgiopac/opacg/opac.exe", [
    "form_params" => [
        "arg0" => "GUEST",
        "arg1" => "GUESTE",
        "TypeAccess" => "FreeAccess",
        "_errorXsl" => "/opacg/html/common/xsl/error.xsl",
        "_wait" => "6M",
        "_xsl" => "/opacg/html/search/xsl/search_results.xsl",
        "_version" => "2.0.0",
        "_service" => "STORAGE:opacfindd:FindView",
        "outform" => "SHOTFORM",
        "length" => "15",
        "query/body" => "%28TI+%CE%E1%EB%EE%EC%EE%E2%29",
        "query/open" => "{NC:<span class='red_text'>}",
        "query/close" => "{NC:</span>}",
        "userId" => "GUEST",
        "session" => "495180",
        "iddb" => "5",
        "level[0]" => "Full",
        "level[1]" => "Retro"
    ]
]);

// Выводим ответ
echo $response->getBody();

What is missing?
UPD
There was not enough data that is transferred from opac.rgub.ru/opacg/guest.html to opac.rgub.ru/cgiopac/opacg/opac.exe :
"arg0" => "GUEST",
"arg1" => "GUESTE", 
"TypeAccess" => "FreeAccess"

Already better. Instead of "Insufficient input. Return to search." html is displayed but nothing is displayed on the page.
I'm trying to parse the title of the first book in the search results, nothing is displayed.
// Находим нужное из хтмла выдачи
$htmlRGBM = $response->getBody();
$docRGBM = new DOMDocument();
@$docRGBM->loadHTML($htmlRGBM);

$xpathRGBM = new DOMXpath($docRGBM);
echo $xpathRGBM->query('//entry[1]/text()')[0]->nodeValue;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Kubintsev, 2018-05-04
@akubintsev

Look in development tools what request flies to the server.
The first thing I noticed was the encoding of the query/body parameter through urlencode.
Next, try throwing headers: referer and user-agent at least.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question