2011-11-29 109 views
1

请帮我解决我的代码如何解决fsockopen错误?

$fp = fsockopen("projecthoneypot.org/statistics.php", 80, $errno, $errstr, 5); 

if ($fp) { 
    $url = "/"; 

    fputs($fp, "GET $url HTTP/1.1\r\nHost: {projecthoneypot.org/statistics.php}\r\nConnection: close\r\n\r\n"); 
    $resp = ''; 

    while(!feof($fp)) { 
     $resp .= fgets($fp, 1024); 
    } 

    echo "$resp"; 
} 

我总是得到这个错误

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/xxx/public_html/xxx.php on line 3 

Warning: fsockopen() [function.fsockopen]: unable to connect to projecthoneypot.org\statistics.php:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /home/xxx/public_html/xxx.php on line 3 

有什么问题吗?

+1

可能重复的问题:[php_network_getaddresses:失败的getaddrinfo:产品名称或服务不知道(http://stackoverflow.com/questions/2661546/php-network-getaddresses -getaddrinfo-failed-name-or-service-not-known) – Wiseguy

+0

谢谢Wiseguy – Maroman

回答

4

使用fsockopen,只需要传递ip/hostname即可。

尝试改变:

$fp = fsockopen("projecthoneypot.org/statistics.php", 80, $errno, $errstr, 5); 
// to 
$fp = fsockopen("projecthoneypot.org", 80, $errno, $errstr, 5); 

当你的HTTP请求的一部分,主持人:应该只projecthoneypot.org,不projecthoneypot.org/statistics.php。

$网址大概应该是/statistics.php

+0

刚刚投了票(因为它是正确的答案) – symcbean

+0

你是一个伟大的人!非常感谢你drew010。问候 – Maroman