2

we are have next headers when we send post:

POST http://www.autonavigator.ru/dispatcher.pl HTTP/1.1
Host: www.autonavigator.ru
Connection: keep-alive
Content-Length: 55
Origin: http://www.autonavigator.ru
X-Request: JSON
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36
Content-type: application/x-www-form-urlencoded; charset=UTF-8
Accept: application/json
X-Requested-With: XMLHttpRequest
Referer: http://www.autonavigator.ru/my/offer_add/
Accept-Encoding: gzip,deflate
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: region_id=45; city_id=22; user_name=rora%40gmail.com; user_type=user; user_offer_count=1; user_message_count=0; user_no_confirm=1; session_id=WR9q4d41DgD7biTOOsMzgtXfJm83VFQn; USession=WR9q4d41DgD7biTOOsMzgtXfJm83VFQn; _ym_visorc_5781676=b

class=list&method=make&show_all=1&vehicle=car&type=used

I would like emulate browser with curl.

For this i use next code:

$ch = curl_init('http://www.autonavigator.ru/dispatcher.pl');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36"); 
$headers = array
(
    'Accept: application/json',
    'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4',
    'Accept-Encoding: gzip,deflate',
    'Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7'
); 

curl_setopt($ch, CURLOPT_HTTPHEADER,$headers); 
curl_setopt($ch, CURLOPT_REFERER, "http://www.autonavigator.ru/my/offer_add/");
curl_setopt($ch, CURLOPT_POSTFIELDS, 'class=list&method=make&show_all=1&vehicle=car&type=used');

$result = curl_exec($ch);
curl_close($ch);

var_dump($result);

But in result we get some errors(https://i.sstatic.net/zWkdP.png):

enter image description here

Tell me please where error in code an how will be right ?

1 Answer 1

2

Most likely like the content is gzipped, so you just need to do:

curl_setopt($ch,CURLOPT_ENCODING , "gzip");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.