Query statement of QQ number query result
21117217 gif89aj http://wpa.qq.com/pa? P = 1: 1: 21117217: 3
195651222 gif89ak http://wpa.qq.com/pa? P = 1: 1: 252520115: 3
426002343 gif89aj http://wpa.qq.com/pa? P = 1: 1: 4366727: 3
/// Add reference
Using system. IO;
Using system. net;
Using system. text;
// Button event
Private void button3_click (Object sender, system. eventargs E)
{
If (textbox3.text = "")
{
MessageBox. Show ("the QQ number of the current query is required! "," Error message! ");
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 + "not online", "QQ status prompt! ");
Break;
Case "gif89aj": MessageBox. Show (strqq + "not online", "QQ status prompt! ");
Break;
}
}
}
// Call a function
// Obtain the HTML source code of the webpage based on the URL
Private string getwebcontent (string URL)
{
String strresult = "";
Try
{
Httpwebrequest request = (httpwebrequest) webrequest. Create (URL );
// Declare an httpwebrequest request
Request. Timeout = 30000;
// Set the connection timeout
Request. headers. Set ("Pragma", "No-Cache ");
Httpwebresponse response = (httpwebresponse) request. getresponse ();
Stream streamreceive = response. getresponsestream ();
Encoding encoding = encoding. getencoding ("gb2312 ");
Streamreader = new streamreader (streamreceive, encoding );
Strresult = streamreader. readtoend ();
}
Catch
{
MessageBox. Show ("error ");
}
Return strresult;
}