douxuan1284 2012-11-02 06:50
浏览 762

Php curl返回不完整的数据

I am trying to login a site with username and password with php curl.

<?php
$url = 'http://XXXXX.com/login';
$ch = curl_init();
$formFields = array('username' => 'XXXX', 'password' => 'WAO', 'button' => 'Login');
$cookiefile = 'C:/wamp/www/tests/cookies.txt';

curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $formFields);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);

echo $response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

But I am not getting complete html in $response. Mean if in browser i am getting 1000 lines in html. In curl I am getting around 350 lines of html.

It was working before but suddenly stopped working.

Any help?

  • 写回答

2条回答 默认 最新

  • doutang7415 2012-11-02 06:58
    关注

    The server could be responding with a meta refresh or an error of some sort. Check the response headers...it's a good place to start

    $response = curl_exec($ch);
    print_r(curl_getinfo($ch));
    

    You should also be sending your post fields as a string, not an array by using http_build_query()

    $formFields = http_build_query( array('username' => 'XXXX', 'password' => 'WAO', 'button' => 'Login'));
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!