I
I
iron69692018-09-25 11:40:36
PHP
iron6969, 2018-09-25 11:40:36

How to send ajax to a third party server?

I made a script on my server that will redirect requests, but something went wrong(
Here is an example of a script
$postdata = http_build_query(
array(
'string' => 'Volume',
'with_villages' => 'true',
'not_only_with_offers' = > 'true'
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Accept: */* \r\n
Accept-Encoding: gzip, deflate , br \r\n
Accept-Language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7 \r\n
Connection: keep-alive \r\n
Content-Length:53 \r\n
content-type: application/x-www-form-urlencoded;charset=UTF-8 \r\n
Cookie: gradient=200; suid=2574aa39b73cbb8d4b715d54441d738c.efac56c3c691fdbf3e9ca469e2ca9b30; autoruuid=g5b9aa5512tq48rla54rmr3ghjebj7n6.30471ec6d7598efaae840b31ea7daa85; cto_lwid=e8c11d42-2660-4128-ae1a-1cd07c7dd6e2; _ym_uid=1536861527376088294; _ym_d=1536861527; autoru_sid = a% 3Ag5b9aa5512tq48rla54rmr3ghjebj7n6.30471ec6d7598efaae840b31ea7daa85% 7C1537539894233.604800.Pc4FrBoH_40wX1jKQt6P_Q.2hD7sT4LTQv7vyTUT_ZuY5nZnOhy2vCmqB1r1xLeSRw; yandexuid=4186291201519418362; my=YwA%3D; guides=; _csrf_token=190b4dd0a78d10f9866252f03f5192c7e88db81911132ef0; from=google-search; counter_ga_all7=1; X-Vertis-DC=sas; rheftjdd=rheftjddVal; _ym_wasSynced=%7B%22time%22%3A1537812410095%2C%22params%22%3A%7B%22eu%22%3A0%7D%2C%22bkParams%22%3A%7B%7D%7D; _gcl_aw=GCL.1537812414.Cj0KCQjwlqLdBRCKARIsAPxTGaUHyYOABd8XtDQk_MTqPM9Pyn2ymVRAAlIYxA5RL0VSypawJx1Psv4aApUIEALw_wcB; _ym_isad=2; from_lifetime=1537812848908 \r\n
Host: auto.ru \r\n
Origin: https://auto.ru \r\n
Referer: https://auto.ru/cars/vaz/all/?sort=fresh_relevance... \r\n
User -Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36 \r\n x
-csrf-token: 190b4dd0a78d10f9866252f03f5192c7e88db813
-with: fetch \r\n',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents(' https://auto.ru/-/ajax/regionsSuggest/index.php ', false, $context);
echo $result;
But the answer is empty, and if you remove "Host: auto.ru \r\n" then it won't let you.
Can someone tell me what is wrong.
In general, this is an attempt to use the city search handler with the author via file_get_contents or CURL

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GonzoTheJudge, 2018-09-28
@GonzoTheJudge

where
did x-csrf-token come from: 190b4dd0a78d10f9866252f03f5192c7e88db81911132ef0 \r\n
do you think it's valid?
a similar situation is discussed here: https://stackoverflow.com/questions/12173990/how-c...

D
Dmitry Baskakov, 2018-09-29
@dmitrybascacov

csrf is a token that is generated when the page is loaded.
You may need to go to the source page where this request is made and find the token in the meta headers there. Then pick up the cookies, because they can also contain a token.
After that, if everything goes right, use the token and mb the 2nd such token. They are just sometimes given a couple.
Do all this every time you access the site.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question