如果这是他们的话,我已经多次问过我的主人了,他们说没有。 cURL中的所有内容都在工作/启用; 然而,每当我尝试以下代码时,我都无法获得连接或页面返回(我已经测试了许多不同的工作代理)。
<?php
//THIS IS A TEST
$ch = curl_init('http://www.google.com');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1');
curl_setopt($ch, CURLOPT_PROXY, '114.80.136.112:7780');
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_exec($ch);
echo curl_error($ch);
print_r(curl_getinfo($ch));
curl_close($ch);
?>
其他人可以为我测试这个功能,看看他们是否有任何工作结果?
编辑:还试过
<?php
//THIS IS A TEST
$ch = curl_init('http://www.google.com');
$f = fopen('requests.txt', 'w');
curl_setopt_array($ch, array(
CURLOPT_PROXY => '114.80.136.112:7780',
CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1',
CURLOPT_TIMEOUT => 40,
CURLOPT_VERBOSE => 1,
CURLOPT_STDERR => $f,
));
curl_exec($ch);
fclose($f);
echo curl_error($ch);
print_r(curl_getinfo($ch));
curl_close($ch);
?>
在 results.txt
中返回了此内容* About to connect() to proxy 114.80.136.112 port 7780 (#0)
* Trying 114.80.136.112...
* Timeout
* connect() timed out!
* Closing connection #0
答案 0 :(得分:0)
返回
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.com.hk/url?sa=p&hl=zh-CN&pref=hkredirect&pval=yes&q=http://www.google.com.hk/&ust=1373746017821152&usg=AFQjCNG2MqAeEfu9C9h5dmJu1n0YZWm5vw">here</A>.
</BODY></HTML>
Array
(
[url] => http://www.google.com
[content_type] => text/html; charset=UTF-8
[http_code] => 302
[header_size] => 580
[request_size] => 191
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.733
[namelookup_time] => 0
[connect_time] => 0.328
[pretransfer_time] => 0.328
[size_upload] => 0
[size_download] => 376
[speed_download] => 512
[speed_upload] => 0
[download_content_length] => 376
[upload_content_length] => 0
[starttransfer_time] => 0.733
[redirect_time] => 0
[certinfo] => Array
(
)
[redirect_url] => http://www.google.com.hk/url?sa=p&hl=zh-CN&pref=hkredirect&pval=yes&q=http://www.google.com.hk/&ust=1373746017821152&usg=AFQjCNG2MqAeEfu9C9h5dmJu1n0YZWm5vw
)
尝试检查phpinfo();
答案 1 :(得分:0)
您可能还需要设置PROXY TYPE:
curl_setopt( $curl_handle, CURLOPT_PROXY, '127.0.0.1:9050' );
curl_setopt( $curl_handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5 );
另外,对于调试,fiddler是非常宝贵的。有了它,您可以制作HTTP请求(甚至使用HTTPS的服务)来对远程服务进行故障排除。
您应该能够使用this method生成curl发送给您的代理的完整请求消息。
最后,尽管在这种情况下这可能对您没有帮助,但我在PHP中编写了一个独立的curl包装类。添加方法或使用as可以让我更容易使用curl。
https://github.com/homer6/altumo/blob/master/source/php/Http/OutgoingHttpRequest.md
https://github.com/homer6/altumo/blob/master/source/php/Http/OutgoingHttpRequest.php