title: 400 Bad Request with Curl Php SSL Authentication
body: <p>I'm getting crazy! I read a thousand post about 400 Bad Request error with Curl PHP for SSL Auth, but I never found an exhaustive answer.</p>
  
  <p>So this is my snippet: </p>
  
  <pre><code>ini_set('display_errors','On');
  error_reporting(E_ALL);
  
  $username=''; // To Set
  $password=''; //To Set
  
  // CODICE DAVIDE
  
   $ch = curl_init();//
   curl_setopt($ch, CURLOPT_URL, 'https://webstudenti.unica.it/esse3/Home.do');
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_HEADER, true);
   curl_setopt($ch, CURLOPT_COOKIESESSION, true);
   curl_setopt($ch, CURLOPT_VERBOSE, true);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
   $response = curl_exec($ch);
  
   preg_match("/Set-cookie: (.*)\n/iU", $response, $matches);
   $cookie = trim(substr($matches[1], strpos($matches[1],':')));
  
   $url = "https://webstudenti.unica.it/esse3/auth/Logon.do";
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
   curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password);
   curl_setopt($ch, CURLOPT_HEADER, true);
   curl_setopt($ch, CURLOPT_COOKIE, $cookie);
   curl_setopt($ch, CURLOPT_COOKIESESSION, true);
   curl_setopt($ch, CURLOPT_VERBOSE, true);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  
   $response = curl_exec($ch);
   curl_close($ch);
  
   var_dump($response);
  </code></pre>
  
  <p>What can it be? I really can't find a solution. I'm using a Windows Server with Microsoft Azure, Php version: 5.4.
  Thankyou</p>