Fputs GET, чтобы свернуться - PullRequest
       24

Fputs GET, чтобы свернуться

0 голосов
/ 19 февраля 2011

У меня есть этот скрипт, который требует 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 голосов
/ 19 февраля 2011

Если я правильно понимаю ваш вопрос, вы просто ищете, как отправить 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);
...