我需要将以下fsocketopen代码转换为curl,以便我可以使用客户端SSL证书。在SSL关闭的那一刻,我可以让卷曲工作。这是当前的代码略有修改,因为它是一个安全的网站。
$fp = fsockopen("tcp://XX.XXX.XXX.XX", 5025, $errno, $errstr, 4);
if (!$fp)
{
echo "$errstr ($errno)<br />\n";
}
else
{
$out = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>";
$out .= "<LoginRequest>";
$out .= "<UserId>". $userID . "</UserId>";
$out .= "</LoginRequest>";
$myout = chr(strlen($out)/256);
$myout .= chr(strlen($out)%256);
$myout .= $out;
fwrite($fp, $myout);
stream_set_timeout($fp,15);
$in = fread($fp, 11024);
此代码确实有效,但如果不使用带有值的fread,我会使用
while (feof($fp)) {
echo fgets($fp, 256);
}
它不起作用,因为服务器从不发送文件结束,也从不关闭连接(直到3分钟过去)
我尝试使用下面的卷曲,但它只是挂在那里。
$url = "XXX.XX.XXX.XXX";
$port = 5025;
$out = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>";
$out .= "<LoginRequest>";
$out .= "<UserId>". $userID . "</UserId>";
$out .= "</LoginRequest>";
$myout = chr(strlen($out)/256);
$myout .= chr(strlen($out)%256);
$myout .= $out;
// more details at http://php.net/curl
$ch = curl_init();
//curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PORT, $port);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $myout);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $myout);
// fetch response and close the socket
$response = curl_exec($ch);
echo '<pre>', curl_error($ch) . "\n";
curl_close($ch);
echo "response 3 =" . $response;
我得到的错误是
操作在30000毫秒后超时,收到0字节enter code here
有什么想法吗?