萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> .net編程 >> Asp.Net發送ICQ信息

Asp.Net發送ICQ信息

class="area"> 想一想我們在網頁上直接給朋友發送ICQ信息,那是多麼美妙的事情啊。呵呵,在吹牛啊,其實ICQ本來就有在線發送的代碼,不過,這些都是AOL給你寫好的代碼,多沒有意思啊。還是自已寫的比較好,呵呵,廢話少說,大家來看代碼吧 01 <% @ Page Langua 02 ge="C#" %> 03 <% @ Assembly Name="System.Net" %> 04 <% @ Import Namespace="System.Net" %> 05 <% @ Import Namespace="System.Net.Sockets" %> 06 <% @ Import Namespace="System.IO" %> 07 <% @ Import Namespace="System.Text" %> 08 09 <Script Language="C#" Runat="Server"> 10 public void Page_Load(Object src,EventArgs e) 11 { 12 ICQ_Show.Text="如果提交後,在這裡顯示信息"; 13 } 14 15 public void Send_Click(Object sender,EventArgs e) 16 { 17 string sendmsg; 18 string commandmsg; 19 //首先取得要發送的信息 20 commandmsg = "from="+ICQ_Name.Text+"&fromemail="+ICQ_Email.Text+"&subject="; 21 commandmsg += ICQ_Subject.Text+"&body="+ICQ_Message.Text+"&to="+ICQ_Number.Text 22 commandmsg += "&Send=Send+Message"; 23 //然後就是組裝全部的信息 24 sendmsg="POST /scripts/WWPMsg.dll HTTP/1.1\r\n"; 25 sendmsg += "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,"; 26 sendmsg += " application/vnd.ms-excel,"; 27 sendmsg += " application/msword, application/vnd.ms-powerpoint, */*\r\n"; 28 sendmsg += "Accept-Language: zh-cn\r\n"; 29 sendmsg += "Content-Type: application/x-www-form-urlencoded\r\n"; 30 sendmsg += "Accept-Encoding: gzip, deflate\r\n"; 31 sendmsg += "User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows 95)\r\n"; 32 sendmsg += "Host: wwp.icq.com\r\n"; 33 sendmsg += "Content-Length: " + commandmsg.Length + "\r\n"; 34 sendmsg += "Connection: Keep-Alive\r\n\r\n"; 35 sendmsg += commandmsg + "\r\n\r\n"; 36 37 Byte[] arrMsg=Encoding.Default.GetBytes(sendmsg.ToCharArray()); 38 //需要發送的信息處理完畢 39 40 //======下面就是發送這些信息===== 41 //首先是建立一個TCPClient 對象 42 TCPClient tcpc=new TCPClient(); 43 if(0==tcpc.Connect("wwp.icq.com",80)) 44 { 45 Stream sm = tcpc.GetStream(); 46 sm.Write(arrMsg,0,sendmsg.Length); 47 StreamReader sr=new StreamReader(tcpc.GetStream(),Encoding.Default); 48 string strRev=sr.ReadLine(); 49 if(strRev.IndexOf("OK")!=-1) 50 { 51 ICQ_Show.Text="ICQ消息發送成功"; 52 } 53 else 54 { 55 ICQ_Show.Text="ICQ消息發送不成功"; 56 } 57 58 } 59 else 60 { 61 ICQ_Show.Text="ICQ消息發送不成功,無法聯結ICQ服務器"; 62 } 63 //關閉TCP聯結 64 tcpc.Close(); 65 } 66 67 </script> 68 <html> 69 <meta http-equiv="Content-Language"
copyright © 萬盛學電腦網 all rights reserved