سؤال
لدي هذا البرنامج النصي الذي يتطلب 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);
}
المحلول
إذا فهمت سؤالك بشكل صحيح ، كنت تبحث فقط عن كيفية إرسال طلب هتب (هذا ما لديك 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);
لا تنتمي إلى StackOverflow