0

以下のコードをcurlなどで機能させようとしています。curl 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;
4

1 に答える 1

1

http/https をプロトコルとして使用していると仮定すると、次のようなものが機能するはずです。

$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.';
  }
}

別の優れた使いやすいオプションはZend_Http_Client、サポートされているためfsockopencurlコードを変更せずに非常に簡単に切り替えることができます。

于 2010-10-05T06:05:34.037 に答える