Вопрос

У меня есть этот скрипт, который требует 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);
}
Это было полезно?

Решение

Если я правильно понимаю ваш вопрос, вы просто ищете, как отправить 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);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top