命令行卷曲和PHP卷曲返回不同的输出

时间:2014-06-01 11:44:58

标签: php curl

第一个注释行是命令curl行,它获取我需要为cookie获取的确切页面。我想写一个php curl模块,这样我就可以在网页内做一些工作;但是,我的下面的代码检索另一个页面,它是一个"请等待加载页面"没有我需要的JavaScript。

我拆分命令以便于阅读:(这是工作卷曲)

 curl "http://domain/Login.fcgi1"
 -H "Origin: http://domain"
 -H "Accept-Encoding: gzip,deflate,sdch"
 -H "Accept-Language: en-US,en;q=0.8"
 -H "User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36"
 -H "Content-Type: application/x-www-form-urlencoded"
 -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
 -H "Cache-Control: max-age=0"
 -H "Referer: http://domain/responder.fcgi1?winid=1001&winname=Login&slot=1"
 -H "Connection: keep-alive"
 --data "14"%"25username=admin&15"%"25password=admin" --compressed 
 > output.html

这是我的PHP模块,它不返回相同的html输出:(我希望下面的那个返回上面返回的相同值)

<?php
$fp = fopen("tmp/newidu.html", "w");
$ch = curl_init('http://domain/Login.fcgi1');
$headers = array(
'Expect:',
'Origin: http://domain',
'Accept-Language: en-US,en;q=0.8',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Cache-Control: max-age=0',
'Referer: http://domain/responder.fcgi1?winid=1001&winname=Login&slot=1',
'Connection: keep-alive'
);
$user_agent = 'User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36';
$post_array = array(
'14%username' => 'admin',
'15%password' => 'admin'
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_ENCODING,'');
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_USERAGENT,$user_agent);
curl_setopt($ch, CURLOPT_POST,TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_array);
curl_setopt($ch, CURLINFO_HEADER_OUT,TRUE); // TURN ON FOR TSHOOT HEADERS
$response = curl_exec($ch);
var_dump(curl_getinfo($ch, CURLINFO_HEADER_OUT)); // TURN ON FOR TSHOOT HEADERS
$response = curl_exec($ch);
fwrite($fp,$response);
fclose($fp);
?>

0 个答案:

没有答案
相关问题