• 判断QQ是否在线的实现:


    功能说明:

    qq在线就在页面上输出【在线】的字样,qq不在线就输出【不在线】的字样

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Net;
    using System.IO;
    using System.Text;
    
    namespace qqIsonline
    {
        public partial class index : System.Web.UI.Page
        {
            public string sendURL;
            protected void Page_Load(object sender, EventArgs e)
            {
                string qqnum = "2669743225";
                string result = GetQQStatue(qqnum);
                if (result == "1")
                {
                    Response.Write("在线");
                }
                else
                {
                    Response.Write("不在线");
                }
                
            }
    
            /// <summary>
            /// 获得qq是否在线的状态
            /// <param name="qqnum">要判断的q号码</param>
            /// <returns>online[0]=X的字符串,x=1或者x=0</returns>
            public string GetURL(string qqnum)
            {
                string resultStr;
                try
                {
                    sendURL = "http://webpresence.qq.com/getonline?Type=1&" + qqnum + ":";
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sendURL);  //创建一个HttpWebRequest对象
                    HttpWebResponse respone = (HttpWebResponse)request.GetResponse();    //返回来自 Internet 资源的响应。
                    //respone.GetResponseStream()  获取用于写入请求数据的 Stream 对象
                    using (StreamReader stream = new StreamReader(respone.GetResponseStream(), Encoding.Default))
                    {
                        //获取结果
                        resultStr = stream.ReadToEnd();   //读取数据
                        return resultStr;
                    }
                }
                catch (Exception ex)
                {
    
                    Response.Write(ex.Message);    //输出错误信息
                }
    
                return "";
            }
    
            /// <summary>
            /// 获得判定qq是否在线的关键字:0表示不在线,1表示在线
            /// </summary>
            /// <param name="qqnum">要判断的QQ号</param>
            /// <returns>1或是0</returns>
            public string GetQQStatue(string qqnum)
            {
                string str = GetURL(qqnum);
                int index = str.IndexOf('=');
                string strQQStute = str.Substring(index + 1, 1);
                return strQQStute;
            }
        }
    }

    完整代码。直接可以运行的!

    写写博客,方便自己也方便别人!

  • 相关阅读:
    冗余链接-684-并查集
    Chrome浏览器进程
    BFC布局规则
    Front-end 前端优化总结
    Flex弹性布局
    Browse兼容性问题
    组合关系与组合模式
    YUI3组件框架之plugin
    javascript数据类型及转换
    矩阵打印
  • 原文地址:https://www.cnblogs.com/Yisijun/p/4638543.html
Copyright © 2020-2023  润新知