Home >Backend Development >PHP Tutorial > request_by_socket交付数据部行的呢
request_by_socket提交数据部行的呢?
$post_string = "app=socket&version=beta&username=".$userid."&pwd=".$userpwd."";
$re = request_by_socket('xinqq163.com','/api/xinqq_login.php',$post_string);
echo $re;
function request_by_socket($remote_server, $remote_path, $post_string, $port = 80, $timeout = 30)
{
$socket = fsockopen($remote_server, $port, $errno, $errstr, $timeout);
if (!$socket) die("$errstr($errno)");
fwrite($socket, "POST $remote_path HTTP/1.0\r\n");
fwrite($socket, "User-Agent: Socket Example\r\n");
fwrite($socket, "HOST: $remote_server\r\n");
fwrite($socket, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($socket, "Content-length: " . (strlen($post_string) + 8) . '\r\n');
fwrite($socket, "Accept:*/*\r\n");
fwrite($socket, "\r\n");
fwrite($socket, "mypost=$post_string\r\n");
fwrite($socket, "\r\n");
$header = "";
while ($str = trim(fgets($socket, 4096))) {
$header .= $str;
}
$data = "";
while (!feof($socket)) {
$data .= fgets($socket, 4096);
}
return $data;
}
错误提示:
411 Length Required