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'));
    
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?