C#擷取QQ線上狀態代碼

來源:互聯網
上載者:User

QQ號碼  查詢結果 查詢語句
21117217 GIF89aJ http://wpa.qq.com/pa?p=1:21117217:3
195651222 GIF89aK http://wpa.qq.com/pa?p=1: 252520115:3
426002343 GIF89aJ http://wpa.qq.com/pa?p=1: 4366727:3

///添加相關引用

using System.IO;
using System.Net;
using System.Text;

//按鈕事件

private void button3_Click(object sender, System.EventArgs e)
  {
  
   if(textBox3.Text=="")
   {
    MessageBox.Show("必須填寫當前的查詢的QQ號碼!","錯誤提示!");
    textBox3.Focus();
    return;   
   }
   else
   {
    string strQQ=textBox3.Text.Trim();
    string strSearchQQ="http://wpa.qq.com/pa?p=1:"+strQQ+":3";
    string strQQStatus=GetWebContent(strSearchQQ).Substring(0,7);
    switch(strQQStatus)
    {
     case "GIF89aK":MessageBox.Show(strQQ+"不線上","QQ狀態提示!");
      break;
     case "GIF89aJ":MessageBox.Show(strQQ+"不線上","QQ狀態提示!");
      break;          
    }
   }
  }

//調用函數

//根據Url地址得到網頁的html源碼
  private string GetWebContent(string Url)
  {
   string strResult="";
   try
   {
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
    //聲明一個HttpWebRequest請求
    request.Timeout = 30000;
    //設定連線逾時時間
    request.Headers.Set("Pragma", "no-cache");
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    Stream streamReceive = response.GetResponseStream();
    Encoding encoding = Encoding.GetEncoding("GB2312");
    StreamReader streamReader = new StreamReader(streamReceive, encoding);
    strResult = streamReader.ReadToEnd();
   }
   catch
   {
    MessageBox.Show("出錯");
   }
   return strResult;
  }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.