$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
------解决方案--------------------
Content-Length
------解决方案--------------------
411 Length Required:服务器拒绝在没有定义Content-Length头的情况下接受请求. 在添加了表明请求消息体长度的有效Content-Length头之后,客户端可以再次提交该请求。
------解决方案--------------------
1.别把用户名和密码都贴上来,用相同数量*号就看明白了……快去改密码吧
2.HTTP/1.1 200 OK不就是返回正确了么?