With the help of the Curl library I send data, in response I get an error 500. That is, passed the wrong parameter or headers.

How can I check which headers and cookies are being transmitted? And what is missing?

{ $ch = curl_init(); $ref="Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36"; curl_setopt($ch, CURLOPT_URL, $url ); // отправляем на curl_setopt($ch, CURLOPT_HEADER, 1); // пустые заголовки $request = 'Host: gstime.e-autopay.com Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Encoding:gzip, deflate, sdch Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4 Cache-Control:max-age=0 Origin:https://gstime.e-autopay.com Referer:https://gstime.e-autopay.com/adminka/login Content-Type:application/x-www-form-urlencoded Connection:keep-alive'; $split = explode("\n",$request); curl_setopt ($ch, CURLOPT_HTTPHEADER,$split ); curl_setopt($ch, CURLOPT_USERAGENT, $ref); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // возвратить то что вернул сервер curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // следовать за редиректами curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 40);// таймаут4 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch,CURLOPT_COOKIEFILE,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__ curl_setopt($ch,CURLOPT_COOKIEJAR,dirname(__FILE__).'/cookie.txt'); #PHP>5.3.6 dirname(__FILE__) -> __DIR__ curl_setopt($ch, CURLOPT_POST, $post!==0 ); // использовать данные в post if($post) curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $curl=curl_exec($ch); $data = new simple_html_dom(); $data->load($curl); $status = curl_getinfo($ch); var_dump($status); curl_close($ch); return $data; } 

Sending a trace. data. Cookies to the file are saved correctly.

 $auth = array( 'login'=>'login', 'password'=>'password', '_token'=>$token ); echo request2($url,$auth); 

Who can help with this question? How else can you understand what is wrong?

  • Variable $ url is not enough?) - andreymal

2 answers 2

Put Fiddler. http://www.telerik.com/fiddler

This is a local proxy server. Accordingly, it intercepts and displays all requests passing through it. You can watch them on the Inspectors tab.

Compare what is the difference and pick up the right set of headings.

Right click on the request Replay -> Reissue from composer - the current request will go to the composer tab, where it can be modified and sent again. Thus, either you clean the correct request to the minimum set of headers, or you supplement the wrong one.

  • But I can not find out what requests leave me in cUrl. - Radik Kamalov
  • Curl can not work through a proxy? - Qwertiy
  • and kkuki which are transmitted how to look? - Radik Kamalov
  • @ RadikKamalov, in the appropriate cookie header in the request and set-cookie in the response. In general, I advise you to compare on the raw tab - there the whole request is shown as it is. For the rest, only if there is a suspicion that the data sent by the post is incorrect. By the way, there is a separate tab cookies. - Qwertiy
  • displays nothing. everything is empty. - Radik Kamalov
 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://example.com/answer.php'); curl_setopt($ch, CURLOPT_TIMEOUT, 3); curl_setopt($ch, CURLOPT_USERAGENT, 'Робот'); curl_setopt($ch, CURLINFO_HEADER_OUT, true); $page = curl_exec($ch); $sent_headers = curl_getinfo($ch, CURLINFO_HEADER_OUT); curl_close($ch); echo $sent_headers;