<?php
     error_reporting(0);
     //邮箱用户名(不带@163.com后缀的)
     $user       = 'xx';
     $pass       = 'xx';
     //登陆
     $url            = 'http://reg.163.com/logins.jsp?type=1';
     $ch             = curl_init($url);
     //创建一个用于存放cookie信息的临时文件
     $cookie         = dirname(__file__)."/cookie.txt";
     $referer_login = 'http://mail.163.com';
     //返回结果存放在变量中,而不是默认的直接输出
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_HEADER, true);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_REFERER, $referer_login);
     $fields_post = array(
             'username'=> $user,
             'password'=> $pass,
             'verifycookie'=>1,
             'style'=>-1,
             'product'=> 'mail163',
             'selType'=>-1,
             'secure'=>'on'
     );
     $headers_login = array(
         'User-Agent'        => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0',
         'Referer'           => 'http://mail.163.com'
     );
     $fields_string = '';
     foreach($fields_post as $key => $value)
     {
         $fields_string .= $key . '=' . $value . '&';
     }
     $fields_string = rtrim($fields_string , '&');
     curl_setopt($ch, CURLOPT_COOKIESESSION, true);
     //关闭连接时,将服务器端返回的cookie保存在以下文件中
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_login);
     curl_setopt($ch, CURLOPT_POST, count($fields));
     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
     $result= curl_exec($ch);
     curl_close($ch);
     //跳转
     $url='http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&from=web&df=webmail163';
     $ch = curl_init($url);
     $headers = array(
         'User-Agent'        => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0'
     );
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_HEADER, true);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     //将之前保存的cookie信息,一起发送到服务器端
     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
     $result = curl_exec($ch);
     curl_close($ch);
     //file_put_contents('./result.txt', $result);
     //unlink($cookie);
     print_r($result);  ?>
这个有什么问题?老是400错误。

解决方案 »

  1.   


    HTTP/1.1 302 Moved Temporarily
    Server: Apache-Coyote/1.1
    x-ntes-mailentry-result: LOGIN_AUTHFAIL
    x-ntes-mailentry-location: http://mail.163.com?msg=authfail#return
    p3p: CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR
    Set-Cookie: JSESSIONID=6929A7C04C535D98BD1F8926C6B87D87; Path=/
    Cache-Control: no-store
    Pragma: no-cache
    Expires: Sun, 17 Feb 2013 08:24:59 GMT
    Location: http://mail.163.com?msg=authfail#return
    Content-Type: text/html;charset=utf-8
    Content-Length: 0
    Date: Sun, 17 Feb 2013 08:24:59 GMT