Home  >  Article  >  Backend Development  >  request_by_socket交付数据部行的呢

request_by_socket交付数据部行的呢

WBOY
WBOYOriginal
2016-06-13 12:54:09877browse

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


------解决方案--------------------
Content-Length
------解决方案--------------------
411 Length Required:服务器拒绝在没有定义Content-Length头的情况下接受请求. 在添加了表明请求消息体长度的有效Content-Length头之后,客户端可以再次提交该请求。
------解决方案--------------------
1.别把用户名和密码都贴上来,用相同数量*号就看明白了……快去改密码吧
2.HTTP/1.1 200 OK不就是返回正确了么?
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn