卷曲,没有获得预期的页面数据

I am trying to connect to shopping backet website via curl.

When the http has been connected via CURL, I am not getting expected data return, it say empty basket (with html data).

Here the code:

<?php
   $agents = 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16';
   $cookiesPath = "c:/wamp/www/Order/cookies";

   $postArray['buy'] = "YTsdfjnsdjnfjsdnkjfnkjsdnfjknsdkfnksnkfn53534545=";
   $postData = http_build_query($postArray);

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
   curl_setopt($ch, CURLOPT_HEADER, true);
   curl_setopt($ch, CURLOPT_USERAGENT, $agents);
   curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
   curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "\Entrust.netSecureServerCertificationAuthority.crt");
   curl_setopt($ch, CURLOPT_URL, "https://www.domain-site.com/checkout/checkout.php" );
   curl_setopt($ch, CURLOPT_POST, 1 );
   curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); 
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
   curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
   curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiesPath . "/cookiefile.txt");
   curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiesPath . "/cookiefile.txt");
   curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $postResult  = curl_exec($ch);
   echo $postResult;
?>

Cookies:

www.domain-site.com FALSE   /   FALSE   0   SECURESESSID    e3psta9vbv4kribfi18jlqxxxx
www.domain-site.com FALSE   /checkout/  FALSE   13052850xx  basketStartTime 1305277xxx

Im not getting expected result of html.

On Firefox using firebug, here it the http request:

GET /checkout/checkout.php?buy=YTsdfjnsdjnfjsdnkjfnkjsdnfjknsdkfnksnkfn53534545= HTTP/1.1
Host: www.domain-site.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Cookie: basketStartTime=1305276911; whoson=853-1303405947712; __utma=1.1209994793.1298996427.1305226205.1305276974.7; __utmz=1.1305276974.7.4.utmcsr=exxxxportal.com|utmccn=(referral)|utmcmd=referral|utmcct=/index.php; SECURESESSID=835qpldx8f1qikueau3s9oxxxx; __utmb=1.1.10.1305276974; __utmc=1

HTML data return as expected showing basket information.

Most probably you can't just re-use cookies from the past. They typically identify a session and the session times out.

You should (1) "browse" to the login page, (2) do the login and then (3) do the buy POST. And record and use cookies in all three steps.

If that doesn't work, then erase all cookies from your browers and record a full "manual" session and then make sure your curl-script repeats that sequence.