I have a PHP script which opens http requests by using CURL
: (it also accepts header if it is needed)
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
if ($post_paramtrs) {
curl_setopt($c, CURLOPT_POST, TRUE);
curl_setopt($c, CURLOPT_POSTFIELDS, "var1=bla&" . $post_paramtrs);
}
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:33.0) Gecko/20100101 Firefox/33.0");
curl_setopt($c, CURLOPT_COOKIEJAR, $dirname . 'cookief.txt');
curl_setopt($c, CURLOPT_COOKIEFILE, $dirname . 'cookief.txt');
curl_setopt($c, CURLOPT_MAXREDIRS, 10);
$follow_allowed = (ini_get('open_basedir') || ini_get('safe_mode')) ? false : true;
if ($follow_allowed) {
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
}
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 9);
curl_setopt($c, CURLOPT_REFERER, $url);
curl_setopt($c, CURLOPT_TIMEOUT, 60);
curl_setopt($c, CURLOPT_AUTOREFERER, true);
curl_setopt($c, CURLOPT_ENCODING, 'gzip,deflate');
$data = curl_exec($c);
$status = curl_getinfo($c);
curl_close($c);
It works as well. Now, I want to get the result of linkedin's search. Here is the page you can search. As you see it sends an ajax request to get the data. For example, if you want to search for Peter
, it sends this request:
https://www.linkedin.com/voyager/api/typeahead/hits?q=blended&query=Peter
But when you open it manually, it fails and throws this error:
CSRF check failed.
It means I have to pass this token with along the request:
What's My question? How can I find that token? Noted that it isn't exist in the DOM. Will it be created by JS? Anyway, do you have any clue for me?