N
N
Nikolai Kovalevsky2017-04-27 19:10:37
PHP
Nikolai Kovalevsky, 2017-04-27 19:10:37

How to get result of ajax request?

Faced with the need to parse data from one site, namely livestreamz.net . I decided to implement everything using cURL tools. The problem is that the data output block is loaded here from AJAX. In the process, I went to the loading script ( livestreamz.net/wp-admin/admin-ajax.php ), copied POST and data from HEADER, but the script stubbornly refuses to give me data (both in the browser and via cURL).
In the process, the code led to this form, although it added too much here in the process of finding a solution:

<?php

$curl = curl_init();
$ajaxpost = array(
"action" => "load_events",
"catid" => "all",
"searchevent"=>"",
"timezone" => "+3",
);
$headers = array(
    "POST /wp-admin/admin-ajax.php HTTP/1.1",
    "Host: livestreamz.net",
    "Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3",
    "Accept-Encoding: gzip, deflate",
    "Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
    "Content-Length: 56",
    "Connection: keep-alive",
    "Cache-Control: max-age=0",
    "Accept: */*",
    "Referer: http://livestreamz.net",
    "X-Requested-With: XMLHttpRequest",
    'Cookie: __cfduid=d95956aaa26b79dbad1a96384993998531493297051; advanced_ads_page_impressions=3; __atuvc=3"%"7C17; PHPSESSID=ckulfdc3oiadpip52pcnc4e7g1; _ga=GA1.2.625847550.1493297040; _gat=1; __atuvs=5901f58c7fbdc80d001'
);
curl_setopt($curl, CURLOPT_FAILONERROR, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
curl_setopt($curl, CURLOPT_TIMEOUT, 10); // times out after 4s
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($curl, CURLOPT_URL, "http://livestreamz.net/wp-admin/admin-ajax.php");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $ajaxpost);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0");

$data = curl_exec($curl);
echo $data;

How to be? I would not want to install PhantomJS, because in fact all the data is there. What am I missing? I've been working on this script for two days. Thank you for attention.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
justpusher, 2017-05-04
@Silert

Try copy as curl from the working request in the browser inspector, and then try to repeat this request with console curl. If it works, remove the headers and parameters one by one, so you know what is important and what is not.

S
Sergey, 2017-05-04
@servdo

I am completely sure that there are plugins in php that can work with parsing dynamically created data. Do you write in pure language or do you use a framework?
And about the question, what are you missing, so they can have any kind of request verification. Maybe they check that the request comes only from their site from a specific page, for example. Maybe the Referer header is not enough. I'm not very strong here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question