我想用CURL将检索到的页面写入文件,我编写了一个代码。问题是它适用于我的系统IP,但是当我将CURLOPT_PROXY设置为代理时,代码运行但不向文件写入任何内容,返回空文件。我无法弄清楚问题,我需要你的帮助。
<?php
$header_array[] = "Mime-Version: 1.0";
$header_array[] = "Content-type: text/html; charset=iso-8859-1";
$header_array[] = "Accept-Encoding: compress, gzip";
$fh = fopen('example.txt','w+') or die($php_errormsg);
$c = curl_init('http://example.com/');
curl_setopt($c, CURLOPT_FILE, $fh);
curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($c, CURLOPT_PROXY, '198.136.50.131:7808');
curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0');
curl_setopt($c, CURLOPT_HTTPHEADER, $header_array);
curl_setopt($c, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_exec($c);
curl_close($c);
?>