2010-10-05 89 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