title: PHP Curl and ajax query to ASP.NET page
body: <p>I trying to send ajax query to ASP.NET page.</p>
  
  <p>Algorithm:</p>
  
  <pre><code>1. I have form on my page;
  2. When user filled all fields he clicks submit button;
  3. When submit button is clicked js send ajax request to page on my server (test.php)
  4. test.php sends request to page on other server (ASP.NET). (page results in text/palin if right post fields was sended)
  5. test.php echo result and js callback alert this result;
  </code></pre>
  
  <p>I know that my client side code is working perfectly but server side...
  This is code of server side:</p>
  
  <pre><code>define('POSTURL', 'http://nakolesah.ru/');
  define('POSTVARS', 'ctl00%24sm=ctl00%24contentPlaceHolder%24upnlFilterAuto%7Cctl00%24contentPlaceHolder%24ddlSizeVendorsAuto&amp;__EVENTTARGET=ctl00%24contentPlaceHolder%24ddlSize...
  
  $ch = curl_init(POSTURL);
  curl_setopt($ch, CURLOPT_POST      ,1);
  curl_setopt($ch, CURLOPT_POSTFIELDS    ,POSTVARS);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1); 
  curl_setopt($ch, CURLOPT_HEADER      ,0);  // DO NOT RETURN HTTP HEADERS 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);  // RETURN THE CONTENTS OF THE CALL
  curl_setopt($ch, CURLOPT_REFERER, POSTURL);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Requested-With: XMLHttpRequest', 'X-MicrosoftAjax: Delta=true', 'Host: nakolesah.ru', 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Content-Type: application/x-www-form-urlencoded; charset=utf-8', 'Connection: keep-alive'));
  $Rec_Data = curl_exec($ch);
  echo $Rec_Data;
  die();
  </code></pre>
  
  <p>(request must imitate ajax request)</p>
  
  <p>Result now:</p>
  
  <p>1|#||4|58|pageRedirect||%2fGenericErrorPage.aspx%3faspxerrorpath%3d%2fDefault.aspx|</p>
  
  <p>It seems like an error, coz normal result must give something like html-list.</p>
  
  <p>I copied POST and Header data with help of httpfox.</p>
  
  <p>i tried absolutely imitate my browser when my browser cookies was off:</p>
  
  <pre><code>curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: nakolesah.ru',
                                                 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; uk; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 WebMoney Advisor',
                                                 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                                                 'Accept-Language: uk,ru;q=0.8,en-us;q=0.5,en;q=0.3',
                                                 'Accept-Encoding: gzip,deflate',
                                                 'Accept-Charset: UTF-8,*',
                                                 'Keep-Alive: 115',
                                                 'Connection: keep-alive',
                                                 'X-Requested-With: XMLHttpRequest',
                                                 'X-MicrosoftAjax: Delta=true',
                                                 'Cache-Control: no-cache, no-cache',
                                                 'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
                                                 'Pragma: no-cache'));
  </code></pre>
  
  <p>And it's doesn't working :(</p>
  
  <p>Any idea about sending ajax request to ASP.NET page with help of PHP CURL?</p>