$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

解决方案 »

  1.   

    Content-Length
      

  2.   

    411 Length Required:服务器拒绝在没有定义Content-Length头的情况下接受请求. 在添加了表明请求消息体长度的有效Content-Length头之后,客户端可以再次提交该请求。
      

  3.   

    这就有点难明……
    理论上411就是没有发送长度过去的Content-Type也改大写
    Accept挪到前面,让Content-Length紧接着数据
    另外mypost=$post_string是不是有点奇怪?相当于 mypost=app=socket&version=……
    strlen($post_string) + 8  这个+8是怎么回事?抓包看看你最后发送了什么出去?
      

  4.   

    抓包了 好像也有提示411 Length Required, 不知道怎么改???
      

  5.   

    POST /api/tm_js_login.php HTTP/1.1 Host: www.taom.com.cn Content-type: application/x-www-form-urlencoded Connection: Close Content-Length: 27 username=liao&pwd=zaq123%21 HTTP/1.1 200 OK Server: nginx/1.0.10 Date: Tue, 29 Jan 2013 04:42:28 GMT Content-Type: text/html; charset=utf-8 Transfer-Encoding: chunked Connection: close Vary: Accept-Encoding X-Powered-By: PHP/5.2.17p1 Set-Cookie: PHPSESSID=44ae3bd313c0a1b6c2448e4571acc099; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: DedeUserID=deleted; expires=Mon, 30-Jan-2012 04:42:27 GMT; path=/ Set-Cookie: DedeUserID__ckMd5=deleted; expires=Mon, 30-Jan-2012 04:42:27 GMT; path=/ Set-Cookie: DedeLoginTime=deleted; expires=Mon, 30-Jan-2012 04:42:27 GMT; path=/ Set-Cookie: DedeLoginTime__ckMd5=deleted; expires=Mon, 30-Jan-2012 04:42:27 GMT; path=/ Set-Cookie: DedeUserID=78; expires=Tue, 05-Feb-2013 04:42:28 GMT; path=/ Set-Cookie: DedeUserID__ckMd5=a32a7cbf1681aef1; expires=Tue, 05-Feb-2013 04:42:28 GMT; path=/ Set-Cookie: DedeLoginTime=1359434548; expires=Tue, 05-Feb-2013 04:42:28 GMT; path=/ Set-Cookie: DedeLoginTime__ckMd5=b9425f188ac2c188; expires=Tue, 05-Feb-2013 04:42:28 GMT; path=/ 47 0 完成结束这样算成功吗。。 但好像没有反应的
      

  6.   

    1.别把用户名和密码都贴上来,用相同数量*号就看明白了……快去改密码吧
    2.HTTP/1.1 200 OK不就是返回正确了么?
      

  7.   

    哦哦 谢谢。。 管理修改帖子没有权限的了。 我去改改  是成功了,但那里无法登陆成功的 。 ,最后还是 用UC同步登陆吧了 ...发下代码 ,以后备查看
    <?$data = array(
    'username'=>'username', 
    'pwd'=>'1223355'); 
    while (list($k,$v) = each($data)) {
    $post .= rawurlencode($k)."=".rawurlencode($v)."&";
    }echo $post;
    //exit;$post = substr( $post , 0 , -1 );
    $len = strlen($post);
    //发送
    $host = "www.xinqq163.com";
    $file = "/api/ceshi.php";
    $fp = @fsockopen( $host , 80, $errno, $errstr, 30);
    if (!$fp) {
    echo "$errstr ($errno)\n";
    } else {
    $receive = '';
    $out = "POST $file HTTP/1.1\r\n";
    $out .= "Host: $host\r\n";
    $out .= "Content-type: application/x-www-form-urlencoded\r\n";
    $out .= "Connection: Close\r\n";
    $out .= "Content-Length: $len\r\n";
    $out .="\r\n";
    $out .= $post."\r\n";
    echo($out);
    //exit;
    fwrite($fp, $out);
    while (!feof($fp)) {
    $receive .= fgets($fp, 128);
    }
    fclose($fp);
    }echo $receive;
    echo '完成结束';?>