ASP.NET發(fā)送ICQ信息DIY(1)
發(fā)表時間:2024-06-17 來源:明輝站整理相關軟件相關文章人氣:
[摘要]這里我給大家提供一個很實用的例子,就是在線發(fā)送ICQ信息。想一想我們在網頁上直接給朋友發(fā)送ICQ信息,那是多么美妙的事情啊。呵呵,在吹牛啊,其實ICQ本來就有在線發(fā)送的代碼,不過,這些都是AOL給你寫好的代碼,多沒有意思啊。還是自已寫的比較好,呵呵,廢話少說,大家來看代碼吧<% @ Page La...
這里我給大家提供一個很實用的例子,就是在線發(fā)送ICQ信息。想一想我們在網頁上直接給朋友發(fā)送ICQ信息,那是多么美妙的事情啊。呵呵,在吹牛啊,其實ICQ本來就有在線發(fā)送的代碼,不過,這些都是AOL給你寫好的代碼,多沒有意思啊。還是自已寫的比較好,呵呵,廢話少說,大家來看代碼吧
<% @ Page Language="C#" %>
<% @ Assembly Name="System.Net" %>
<% @ Import Namespace="System.Net" %>
<% @ Import Namespace="System.Net.Sockets" %>
<% @ Import Namespace="System.IO" %>
<% @ Import Namespace="System.Text" %>
<Script Language="C#" Runat="Server">
public void Page_Load(Object src,EventArgs e)
{
ICQ_Show.Text="如果提交后,在這里顯示信息";
}
public void Send_Click(Object sender,EventArgs e)
{
string sendmsg;
string commandmsg;
file://首先取得要發(fā)送的信息
commandmsg = "from="+ICQ_Name.Text+"&fromemail="+ICQ_Email.Text+"&subject=";
commandmsg += ICQ_Subject.Text+"&body="+ICQ_Message.Text+"&to="+ICQ_Number.Text
commandmsg += "&Send=Send+Message";
file://然后就是組裝全部的信息
sendmsg="POST /scripts/WWPMsg.dll HTTP/1.1\r\n";
sendmsg += "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,";
sendmsg += " application/vnd.ms-excel,";
sendmsg += " application/msword, application/vnd.ms-powerpoint, */*\r\n";
sendmsg += "Accept-Language: zh-cn\r\n";
sendmsg += "Content-Type: application/x-www-form-urlencoded\r\n";
sendmsg += "Accept-Encoding: gzip, deflate\r\n";
sendmsg += "User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows 95)\r\n";
sendmsg += "Host: wwp.icq.com\r\n";
sendmsg += "Content-Length: " + commandmsg.Length + "\r\n";
sendmsg += "Connection: Keep-Alive\r\n\r\n";
sendmsg += commandmsg + "\r\n\r\n";
Byte[] arrMsg=Encoding.Default.GetBytes(sendmsg.ToCharArray());
file://需要發(fā)送的信息處理完畢
file://======下面就是發(fā)送這些信息=====
file://首先是建立一個TCPClient 對象
TCPClient tcpc=new TCPClient();
if(0==tcpc.Connect("wwp.icq.com",80))
{
Stream sm = tcpc.GetStream();
sm.Write(arrMsg,0,sendmsg.Length);
StreamReader sr=new StreamReader(tcpc.GetStream(),Encoding.Default);
string strRev=sr.ReadLine();
if(strRev.IndexOf("OK")!=-1)
{
ICQ_Show.Text="ICQ消息發(fā)送成功";
}
else
{
ICQ_Show.Text="ICQ消息發(fā)送不成功";
}
}
else
{
ICQ_Show.Text="ICQ消息發(fā)送不成功,無法聯(lián)結ICQ服務器";
}
file://關閉TCP聯(lián)結
tcpc.Close();
}
</script>
<html>
<meta http-equiv="Content-Language" content="zh-cn">
<head>
<title></title>
</head>
<body>
<form runat="server" >
<table>
<tr><td align=center colspan=2>
<asp:Label id="ICQ_Show" runat="server" ForeColor="red" /></td></tr>
<tr><td><br></tr>
<tr><td align=center colspan=2>發(fā)送ICQ信息</td></tr>
<tr><td>您的ICQ號:</td><td><asp:TextBox id="ICQ_Number" runat="server" /></td></tr>
<tr><td>您的網名:</td><td><asp:TextBox id="ICQ_Name" runat="server" /></td></tr>
<tr><td>您的Email:</td><td><asp:TextBox id="ICQ_Email" runat="server" /></td></tr>
<tr><td>發(fā)送主題:</td><td><asp:TextBox id="ICQ_Subject" runat="server" /></td></tr>
<tr><td>發(fā)送內容:</td><td><asp:TextBox id="ICQ_Message" runat="server" /></td></tr>
<tr><td><asp:Button OnClick="Send_Click" Text="發(fā)送ICQ信息" RunAt="server" /></td></tr>
</table>
</form>
</body>
</html>