fputs要卷曲

时间:2011-02-19 00:12:47

标签: php curl fgets fputs

我有这个需要allow_url_fopen = On的脚本,这不是一个好主意,我想要更改curl。如果有人能帮我解决fputs GET的问题,我将不胜感激。

$SH = fsockopen($IP, $Port, $errno, $errstr, 30);
echo $errstr;    
#$ch = curl_init();
#curl_setopt($ch, CURLOPT_TIMEOUT, 30);
#curl_setopt($ch, CURLOPT_URL, $IP.":".$Port);
#curl_setopt ($ch, CURLOPT_HEADER, 0);
    if ($SH){ 
        fputs($SH,"GET /7.html HTTP/1.0\r\nUser-Agent: S_Status (Mozilla Compatible)\r\n\r\n");
        $content = "";
        while(!feof($SH)) { 
            $content .= fgets($SH, 1000);
            #content .= curl_setopt($ch, CURLOPT_FILE, $SH);
        }
        fclose($SH);
        #curl_close($ch);
}

1 个答案:

答案 0 :(得分:0)

如果我正确理解了您的问题,那么您只是在寻找如何发送HTTP请求(这就是您fputs($SH, "GET ...")正在做的事情,这是使用curl_exec()完成的。似乎这应该有用。

$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_PORT, $Port);
curl_setopt($ch, CURLOPT_URL, $IP . '/7.html');
curl_setopt($ch, CURLOPT_USERAGENT, 'S_Status (Mozilla Compatible)'); 
//tell curl to return the output, not display it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
//execute the request
$content = curl_exec($ch);