2010-10-05 47 views
0

我正在试着让下面的代码和curl一起工作。我已经看过卷曲fsockopen conversion,但它不起作用。该代码的作品除了在我的主机上禁用fsockopen。任何帮助将不胜感激。fsockopen的其他好选择?

$host = substr($hostport,0,50); 
$port = substr($hostport,50,10); 
$issecure = substr($hostport,60,1); 

if($issecure=="Y") 
{ 
    $host = "ssl://".$host; 
} 
$fsok = fsockopen(trim($host) , intval(trim($port))); 
if(FALSE == $fsok) 
{ 
    echo "Target Host not Found/Down"; return ; 
} 
fwrite($fsok, $bodyData); 
$port ='';$host ='';$hostport= '';$bodyData=''; 

while ($line = fread($fsok, 25000)) 
{ 
    echo $line; 
} 

fclose($fsok); 
return $line; 
+0

请将您的代码格式化为 – 2010-10-05 05:44:46

+0

我该怎么做?真的不明白你的期望.. – Jade 2010-10-20 07:41:26

回答

1

使用假设您选择HTTP/HTTPS像下面的协议somethig应该工作:

$client = curl_init(); 

$options = array(
    CURLOPT_PORT => $port 
    CURLOPT_RENTURNTRANSFER => true, 
    CURLOPT_SSL_VERIFYPEER => false, // dont verify the cert 
    CURLOPT_URL => ($issecure ? 'https://' : 'http://'). $host 
); 

$response = curl_exec($client); 

if(false !== $response) { 
    echo $response; 
    return $response; 
} else { 
    if($error = curl_error($client)) { 
    echo $error; 
    return $error; 
    } else { 
    echo 'Something is wrong. Error could not be determined.'; 
    } 
} 

另一个伟大和许多eaiser使用的办法是Zend_Http_Client支持fsockopencurl这样你就可以来回切换很容易,无需修改代码。

+0

对不起,迟到的答复,试图看看它是否会工作,但它的写作目标主机没有找到..请我粘贴完整的代码给你..谢谢 – Jade 2010-10-20 07:40:21