我尝试通过 PHP fsockopen 连接到服务器,以最初获取基本身份验证的 cookie,然后持久连接到响应的 Location 标头中定义的流服务器。
问题是我的代码在 fgets 上冻结并且从未从目标服务器接收到任何响应数据。我通过 Amazon ec2 实例上的端口 443 上的 https 进行连接。服务器通过我的服务器终端中的 curl 或通过我的 chome 浏览器连接良好。
$this->conn = fsockopen('ssl://[destination_server]', 443, $errNo, $errStr, $this->connectTimeout);
stream_set_blocking($this->conn, 1);
fwrite($this->conn, "GET " . $urlParts['path'] . " HTTP/1.0\r\n");
fwrite($this->conn, "Host: " . $urlParts['host'] . "\r\n");
fwrite($this->conn, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($this->conn, "Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
fwrite($this->conn, 'Authorization: Basic ' . $authCredentials . "\r\n");
fwrite($this->conn, 'User-Agent: ' . self::USER_AGENT . "\r\n");
list($httpVer, $httpCode, $httpMessage) = preg_split('/\s+/', trim(fgets($this->conn, 1024)), 3);
//code never gets here!!!
有什么想法吗?