title: curl .net https page login problem 500 Internal Server Error
body: <p>When I try to login to page with curl I get <strong>500 Internal Server Error</strong>. Page is on https. </p>
  
  <p>Here is Login function:</p>
  
  <pre><code> function login ($login, $pass) {
  
      $loginURL = "https://bitomat.pl/Account/LogOn";
      $loginPage = $this-&gt;curl-&gt;getPage($loginURL);
      $numStart = strpos(htmlentities($loginPage['content']), "type=&amp;quot;hidden&amp;quot; value=&amp;quot;");
      $numEnd = strpos(htmlentities($loginPage['content']), "&amp;lt;fieldset&amp;gt;");
      $verNum = substr(htmlentities($loginPage['content']), $numStart+36, 64);
      echo $numStart." - ".$numEnd." - ".$verNum."&lt;br&gt;";
      $page = $this-&gt;curl-&gt;post($loginURL, "__RequestVerificationToken=".urlencode($verNum)."&amp;UserName=$login&amp;Password=".urlencode($pass)."&amp;RememberMe=false");
  
      echo nl2br(htmlentities($page['content']));
  
  }
  </code></pre>
  
  <p>In response I get:</p>
  
  <pre><code>   HTTP/1.1 500 Internal Server Error
     Cache-Control: private
     Content-Type: text/html; charset=utf-8
     Server: Microsoft-IIS/7.0
     X-AspNetMvc-Version: 2.0
     X-AspNet-Version: 4.0.30319
     X-Powered-By: ASP.NET
     Date: Sat, 25 Jun 2011 16:32:18 GMT
     Content-Length: 3974
  </code></pre>
  
  <p>CUrl post function:</p>
  
  <pre><code>function post($url, $params) {
      $rnd = rand(0, 10000000000);
  
      $options = array(
          CURLOPT_COOKIESESSION =&gt; true,
          CURLOPT_COOKIEFILE =&gt; "cookie/cookieBitomat",// . $rnd,
          CURLOPT_COOKIEJAR =&gt; "cookie/cookieBitomat",// . $rnd,
          CURLOPT_RETURNTRANSFER =&gt; true, // return web page
          CURLOPT_HEADER =&gt; true, // don't return headers
          CURLOPT_FOLLOWLOCATION =&gt; true, // follow redirects
          CURLOPT_POST =&gt; true,
          CURLOPT_POSTFIELDS =&gt; $params,
          CURLOPT_USERAGENT =&gt; "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1", // who am i
          CURLOPT_AUTOREFERER =&gt; true, // set referer on redirect
          CURLOPT_CONNECTTIMEOUT =&gt; 60, // timeout on connect
          CURLOPT_TIMEOUT =&gt; 60, // timeout on response
          CURLOPT_MAXREDIRS =&gt; 20, // stop after 10 redirects
          CURLOPT_SSL_VERIFYPEER =&gt; false,
          CURLOPT_VERBOSE =&gt; TRUE,
          CURLOPT_HTTPHEADER =&gt; array("Content-Type: application/x-www-form-urlencoded",
              "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
              "Host: bitomat.pl",
              "Accept-Language: pl,en-us;q=0.7,en;q=0.3",
              "Accept-Encoding: gzip, deflate",
              "Accept-Charset: ISO-8859-2,utf-8;q=0.7,*;q=0.7",
              "Keep-Alive: 115",
              "Connection: keep-alive",
              "Referer: https://bitomat.pl/Account/LogOn"
              )
      );
  
  
      $ch = curl_init($url);
      curl_setopt_array($ch, $options);
      $content = curl_exec($ch);
      $err = curl_errno($ch);
      $errmsg = curl_error($ch);
      $header = curl_getinfo($ch);
      curl_close($ch);
  
      $header['errno'] = $err;
      $header['errmsg'] = $errmsg;
      $header['content'] = $content;
      return $header;
  }
  </code></pre>