liu122613153B 2013-08-23 02:33 采纳率: 0%
浏览 4849

发送http请求返回{"retcode":103,"errmsg":""}

我模仿一个QQ登录的按钮功能 为什么返回的{"retcode":103,"errmsg":""}
代码如下:

            try
            { 
            //发送请求地址
            string url2 = ptsig;

            string strHtmlContent2 = "";//接收返回数据
            HttpWebRequest webRequest2 = WebRequest.Create(url2) as HttpWebRequest;//发送请求

            webRequest2.Method = "GET";//请求方法
            webRequest2.Referer = "http://d.web2.qq.com/proxy.html";//页面链接

            webRequest2.ContentType = "application/x-www-form-urlencoded";//内容类型
            //webRequest2.Timeout = 2000;//响应时间
            webRequest2.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)";//客户端浏览器的原始用户代理信息

            webRequest2.CookieContainer = cookies;//获取cookie


            HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();//获得服务器响应对象 
            Stream resStream2 = response2.GetResponseStream();//转成流对象  
            StreamReader sr2 = new StreamReader(resStream2, Encoding.UTF8);//创建只读流对象
            strHtmlContent2 = sr2.ReadToEnd();
            response2.Close();//关闭流对象
            webRequest2.Abort();//关闭请求
        }
        catch (Exception e)
        {
            Msg = "qq:" + _qqno + "登陆" + e.Message;
            return false;

        }

        try
        {
            //发送请求地址
            string url2 = "http://d.web2.qq.com/channel/login2";

            string strHtmlContent2 = "";//接收返回数据
            HttpWebRequest webRequest2 = WebRequest.Create(url2) as HttpWebRequest;//发送请求

            webRequest2.Method = "POST";//请求方法

            //webRequest2.Referer = "http://d.web2.qq.com/proxy.html";//页面链接
            webRequest2.Referer = "http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=2";

            webRequest2.ContentType = "application/x-www-form-urlencoded";//内容类型
            //webRequest2.Timeout = 2000;//响应时间
            webRequest2.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)";//客户端浏览器的原始用户代理信息

            webRequest2.CookieContainer = cookies;//获取cookie

            //上传数据
            string postData = "r={\"status\":\"online\",\"ptwebqq\":\"" + ptwebqq + "\",\"passwd_sig\":\"\",\"clientid\":\"" + clientid + "\",\"psessionid\":null}";

            // Encode the data
            byte[] encodedBytes = Encoding.UTF8.GetBytes(postData);//转成二进制数组
            webRequest2.ContentLength = encodedBytes.Length;//字节数

            // Write encoded data into request stream
            Stream requestStream = webRequest2.GetRequestStream();//转成流对象
            requestStream.Write(encodedBytes, 0, encodedBytes.Length);
            requestStream.Close();//关闭流并释放资源

            HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();//获得服务器响应对象 
            Stream resStream2 = response2.GetResponseStream();//转成流对象  
            StreamReader sr2 = new StreamReader(resStream2, Encoding.UTF8);//创建只读流对象
            strHtmlContent2 = sr2.ReadToEnd();
            response2.Close();//关闭流
            webRequest2.Abort();//关闭请求
            if (strHtmlContent2.IndexOf("vfwebqq") > -1)
            {
                //获取第二次登录用户进行QQ号的操作
                vfwebqq = new Regex("vfwebqq\":\"[^\"]+").Match(strHtmlContent2).Value.Replace("vfwebqq\":\"", "");
                psessionid = new Regex("psessionid\":\"[^\"]+").Match(strHtmlContent2).Value.Replace("psessionid\":\"", "");
                Msg = "qq:" + _qqno + "登陆webqq成功";
                return true;
            }
            else
            {
                Msg = "qq:" + _qqno + "登陆受限";
                return false;
            }
        }
        catch (Exception e)
        {
            Msg = "qq:" + _qqno + "登陆" + e.Message;
            return false;

        }
  • 写回答

1条回答

  • HaiChecker 2015-12-25 11:11
    关注

    没有把cookie带上

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘