PHP卷曲问题加载空白页

时间:2014-04-09 19:10:15

标签: php curl

我正试图通过这个片段显示一个表格,我似乎无法让它显示出来。它加载一个空白页面。当我转到URL本身时,它会加载模板,但是想要从URL中提取表并使用php显示。

有人可以给我指点吗?

这是代码

<?php
$handle = curl_init();
curl_setopt ($handle, CURLOPT_URL," https://api.aghost.net/api/futures/index.cfm/");
curl_setopt ($handle, CURLOPT_POSTFIELDS,     "username=E006520104&password=KRKwev!96&service=table&symbols=@LE6,@GF6,@KW6,@C6,@S6&style=6&layout=grouped&tableWidth=350px&fontSize=0.65em&firstColLabel=Month&oddRowBgColor=%23EAEAEA&columns=high,low,last,change&commRowBgColor=%23009900&commRowTextColor=%23FFFFFF&labelTextColor=%23009900&exchangeByComm=1");
curl_setopt ($handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt ($handle, CURLOPT_FRESH_CONNECT, TRUE);
curl_exec ($handle);
curl_close($handle);
?>

2 个答案:

答案 0 :(得分:2)

试试这个 - &gt;

<?php
$handle = curl_init();
curl_setopt ($handle, CURLOPT_URL,"https://api.aghost.net/api/futures/index.cfm/");
curl_setopt($handle,CURLOPT_POST, 1);
curl_setopt ($handle, CURLOPT_POSTFIELDS,     "username=E006520104&password=KRKwev!96&service=table&symbols=@LE6,@GF6,@KW6,@C6,@S6&style=6&layout=grouped&tableWidth=350px&fontSize=0.65em&firstColLabel=Month&oddRowBgColor=%23EAEAEA&columns=high,low,last,change&commRowBgColor=%23009900&commRowTextColor=%23FFFFFF&labelTextColor=%23009900&exchangeByComm=1");
curl_setopt ($handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt ($handle, CURLOPT_FRESH_CONNECT, TRUE);
$output = curl_exec ($handle);
curl_close($handle);
echo $output;
?>

如果它仍然可以工作,那么你卷曲的网站需要使用useragent变种。在这种情况下,使用CURLOPT_USERAGENT

答案 1 :(得分:1)

当您将选项CURLOPT_RETURNTRANSFER设置为true curl_exec时,将返回结果数据而不是将其转储。

Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure.

CURLOPT_RETURNTRANSFER设置为false,或者在收到结果后存储并打印结果。