Php 警告:fsockopen():无法连接到http://test6/:80 (找不到套接字传输“http”;
我尝试在本地服务器上使用下面的代码Php 警告:fsockopen():无法连接到http://test6/:80 (找不到套接字传输“http”;,php,sockets,Php,Sockets,我尝试在本地服务器上使用下面的代码 <?php $hostname = "http://test6/"; $path = "/test6/handler.php"; $line = ""; $fp = fsockopen($hostname, 80, $errno, $errstr, 30); if (!$fp) echo "$errstr ($errno) <br />\n"; else { $data = "name=".urlencode("TestName"
<?php
$hostname = "http://test6/";
$path = "/test6/handler.php";
$line = "";
$fp = fsockopen($hostname, 80, $errno, $errstr, 30);
if (!$fp) echo "$errstr ($errno) <br />\n";
else
{
$data = "name=".urlencode("TestName")."&pass=".urlencode("TestPassword")."\r\n\r\n";
$headers = "POST $path HTTP/1.1\r\n";
$headers .= "Host: $hostname\r\n";
$headers .= "Content-type: application/x-www-form-urlencoded; ; charset=utf-8\r\n";
$headers .= "Content-Length: ".strlen($data)."\r\n\r\n\r\n";
fwrite($fp, $headers.$data);
while (!feof($fp))
{
$line .= fgets($fp, 1024);
}
fclose($fp);
}
echo $line;
?>
但结果我得到了
警告:fsockopen():无法连接到http://test6/:80(找不到套接字传输“http”-配置PHP时是否忘记启用它?)在C:\Winginx\home\test6\public\u html\index.PHP的第6行找不到套接字传输“http”-配置PHP时是否忘记启用它?(11477112)
php.ini
中的extension=php\u openssl.dll
已启用
有人能告诉我怎么做吗?删除
http://
和后面的斜杠。我应该是test6
。您需要的是主机名,而不是协议信息。在POST数据之前,您还有太多的\r\n