【发布时间】:2016-07-14 10:09:48
【问题描述】:
我正在尝试获取一个带有请求 xml 的 zip 文件(我以前不知道大小和名称),该请求 xml 向我返回了一个 zip 文件。我想下载它,但有时全部下载(大约 16mb)有时不下载(2mb 或 4mb 或 1mb)我不知道为什么。
这是我的代码:
$ch2=curl_init();
curl_setopt($ch2, CURLOPT_URL, $this->URL);
curl_setopt($ch2, CURLOPT_TIMEOUT, 5040);
curl_setopt($ch2, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS,$this->XMLRequest);
curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch2, CURLOPT_SSLVERSION, 3);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true);
$xml = curl_exec($ch2);
curl_close($ch2);
$file2 = fopen('upload/item.zip','w+');
fwrite($file2, $xml);
fclose($file2);
我也试过了:
file_put_contents('upload/item.zip', $xml);
有人可以帮我吗?
【问题讨论】:
-
我没有在你的代码中看到 curl_exec?是 $xml = curl_exec( $ch2 );
-
编辑问题我缺少一行@Dexa