douyue2313 2011-05-13 09:13
浏览 60
已采纳

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

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.

  • 写回答

1条回答 默认 最新

  • dsjuimtq920056 2011-05-13 11:20
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算