困扰了好久的问题。。代码如下
"; } $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if( $httpcode ==200 ) { echo ($i+1).". $dl $httpcode 成功有些 ip 是能在手机上测试通过的。。换了一个环境跑还是一样结果,所以,是不是代码有些问题╮( •́ω•̀ )╭
1
nmdx OP header('Content-Type: text/html; charset=utf-8');
$ip=array(.......);//ip:port for ($i=0; $i<=count($ip) -1; $i++) { $dl= $ip[$i]; $ch = curl_init(); curl_setopt($ch, CURLOPT_PROXY, $dl ); curl_setopt($ch, CURLOPT_URL, "http://baidu.com"); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt ($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); if (!curl_exec($ch)) { echo ($i+1).". $dl 失败<br>"; } $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if( $httpcode ==200 ) { echo ($i+1).". $dl $httpcode 成功<br>"; } } curl_close($ch); |
2
fuxkcsdn 2017-07-23 09:14:01 +08:00 via iPhone
$ip=array(.......);//ip:port
改为 $ip=array(.......);// http://ip:port |
3
VgV 2017-07-23 13:46:05 +08:00
@fuxkcsdn 不用加 http://也是可以的,原因是他漏写了一段代码。
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); |
4
nmdx OP @VgV 应该不是这个问题。。CURLOPT_PROXYTYPE 的默认值不就是 CURLPROXY_HTTP 嘛。。添加已测试。。
加了一下 curl_error 如下: 1Failed to connect to 189.17.39.3 port 8080: Connection refused. 189.17.39.3:8080 失败 2Failed to connect to 97.72.129.38 port 87: Connection refused. 97.72.129.38:87 失败 3Failed to connect to 139.59.110.186 port 8080: Connection refused. 139.59.110.186:8080 失败 4Failed to connect to 122.241.74.202 port 808: Connection refused. 122.241.74.202:808 失败 5Failed to connect to 112.74.50.191 port 8888: Connection refused. 112.74.50.191:8888 失败 6Failed to connect to 218.75.101.66 port 3128: Connection refused. 218.75.101.66:3128 失败 7Failed to connect to 115.207.81.119 port 808: Connection refused. 115.207.81.119:808 失败 8Failed to connect to 59.62.164.37 port 808: Connection refused. 59.62.164.37:808 失败 9. 183.222.102.108:80 200 成功 10Failed to connect to 148.251.160.237 port 3128: Connection refused. 148.251.160.237:3128 失败 ===略 |
5
VgV 2017-07-23 23:17:55 +08:00
@nmdx 不是成功了一个吗,可能是你的这些 IP 有问题,失效了。。
curl_setopt($ch, CURLOPT_PROXY, $proxy);//ip:port curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);//必须要加这行 |
6
fuxkcsdn 2017-07-24 09:29:45 +08:00 via iPhone
|
8
nmdx OP @VgV 因为那个是 80 口的嘛。。。比如这个挂在阿里云的 112.74.50.191:8888 手机可用
p.s.也就是说代码应该是暂时没啥问题了?那可能是环境的问题了。。 没环境测试了(•́ω•̀ ٥) |
9
nmdx OP @VgV ps...你们说的那个 ip:port 的问题。。表示直接一行 curl_setopt($ch, CURLOPT_PROXY, "ip:port" );就可以的。。 大概因为 http 是默认值?
|
10
ja2007gg 2018-04-22 14:20:11 +08:00
请问你解决问题了吗?我也遇到 Curl error: Recv failure: Connection reset by peer 这个问题 而且还没有解决
|