Hello, I can not understand why the query cURL does not return anything, even checked for an error curl_error does not output anything either. What is wrong here? Please help someone understand the topic. By the way, I used the Burp Suite program to track headers; for some reason, there is no 200 in the request status, I don’t know if it matters. Here is my code, password and login, I do not write:

<?php require_once 'vendor/autoload.php'; function request( $url, $post = null, $cookiefile = 'tmp/cookie.txt' ){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36'); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); //curl_setopt($ch, CURLOPT_POST, 1); //curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json; charset=UTF-8', 'X-Requested-With: XMLHttpRequest', 'Accept-Encoding: gzip, deflate', 'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4', 'Accept: application/json, text/javascript, */*; q=0.01', 'Connection:keep-alive', 'Content-Length:122', 'Origin: http://www.3dcontentcentral.com', ]); curl_setopt($ch, CURLOPT_REFERER, 'http://www.3dcontentcentral.com/default.aspx'); curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8080'); curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); if( $post ){ curl_setopt( $ch, CURLOPT_POSTFIELDS, $post ); } if(curl_exec($ch) === false){ echo 'Ошибка curl: ' . curl_error($ch); }else{ echo 'Операция завершена без каких-либо ошибок'; } $html = curl_exec($ch); curl_close( $ch ); return $html; } file_put_contents('tmp/cookie.txt',''); $post = '{'.'"loginData":'.json_encode([ 'Login' => 'mylogin', 'Password' => "mypass", 'RememberMe' => false, 'LoginAsSupplier'=> false, 'CatalogId' => "" ]).'}'; $html = request('http://www.3dcontentcentral.com/default.aspx/Login', $post); echo $html; 
  • one
    why two times to carry out the curl? try the if (($html = curl_exec($curl)) !== false && $html !== '') {} What is that no echo is displayed? - Jean-Claude
  • Yes, the page is empty and nothing is displayed. - ZaurK
  • Thanks, the code is fixed, but the behavior is the same - all the page is loaded all the time and does not display anything. - ZaurK
  • Removed the lines curl_setopt ($ ch, CURLOPT_PROXY, '127.0.0.1:8080') in the code; curl_setopt ($ ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); Now displays the operation completed without any errors {"d": ""}. - ZaurK

1 answer 1

No need to hardcode Content-Length, remove this header. And another comment was made to you about the double call of curl_exec. Checked through fiddler, everything is sent and received - the code works.

  • Thanks for checking the code, knowing what works is already good. Now to get the result on the screen. If I understand correctly, then the page should be displayed with an authorized user. - ZaurK
  • After authorization it will be possible to have a blank page with a redirect, everything depends on the site. Maybe you were issued cookies after logging in, these cookies can be used for subsequent navigation on the site. - user3416803
  • When I log in to the browser, I don’t watch the redirect, I can log in on any page - the same page remains, ajax authorization, cookies are set. - ZaurK
  • one
    But with these cookies, go to the right page - user3416803
  • Thanks, I will try - ZaurK