【 tulaoshi.com - ASP.NET 】
这里我给大家提供一个很实用的例子,就是在线发送ICQ信息。想一想我们在网页上直接给朋友发送ICQ信息,那是多么美妙的事情啊。呵呵,在吹牛啊,其实ICQ本来就有在线发送的代码,不过,这些都是AOL给你写好的代码,多没有意思啊。还是自已写的比较好,呵呵,废话少说,大家来看代码吧 <br
<br
<% @ Page Language="C#" % <br
<% @ Assembly Name="System.Net" % <br
<% @ Import Namespace="System.Net" % <br
<% @ Import Namespace="System.Net.Sockets" % <br
<% @ Import Namespace="System.IO" % <br
<% @ Import Namespace="System.Text" % <br
<br
<Script Language="C#" Runat="Server" <br
public void Page_Load(Object src,EventArgs e) <br
{ <br
ICQ_Show.Text="如果提交后,在这里显示信息"; <br
} <br
<br
public void Send_Click(Object sender,EventArgs e) <br
{ <br
string sendmsg; <br
string commandmsg; <br
//首先取得要发送的信息 <br
commandmsg = "from="+ICQ_Name.Text+"&fromemail="+ICQ_Email.Text+"&subject="; <br
commandmsg += ICQ_Subject.Text+"&body="+ICQ_Message.Text+"&to="+ICQ_Number.Text <br
commandmsg += "&Send=Send+Message"; <br
//然后就是组装全部的信息 <br
sendmsg="POST /scripts/WWPMsg.dll HTTP/1.1rn"; <br
sendmsg += "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,"; <br
sendmsg += " application/vnd.ms-excel,"; <br
sendmsg += " application/msword, application/vnd.ms-powerpoint, */*rn"; <br
sendmsg += "Accept-Language: zh-cnrn"; <br
sendmsg += "Content-Type: application/x-www-form-urlencodedrn"; <br
sendmsg += "Accept-Encoding: gzip, deflatern"; <br
sendmsg += "User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows 95)rn"; <br
sendmsg += "Host: wwp.icq.comrn"; <br
sendmsg += "Content-Length: " + commandmsg.Length + "rn"; <br
sendmsg += "Connection: Keep-Alivernrn"; <br
sendmsg += commandmsg + "rnrn"; <br
<br
Byte[] arrMsg=Encoding.Default.GetBytes(sendmsg.ToCharArray()); <br
//需要发送的信息处理完毕 <br
<br
//======下面就是发送这些信息===== <br
//首先是建立一个TCPClient 对象 <br
TCPClient tcpc=new TCPClient(); <br
if(0==tcpc.Connect("wwp.icq.com",80)) <br
{ <br
Stream sm = tcpc.GetStream(); <br
sm.Write(arrMsg,0,sendmsg.Length); <br
StreamReader sr=new StreamReader(tcpc.GetStream(),Encoding.Default); <br
string strRev=sr.ReadLine(); <br
if(strRev.IndexOf("OK")!=-1) <br
{ <br
ICQ_Show.Text="ICQ消息发送成功"; <br
} <br
else <br
{ <br
ICQ_Show.Text="ICQ消息发送不成功"; <br
} <br
<br
} <br
else <br
{ <br
ICQ_Show.Text="ICQ消息发送不成功,无法联结ICQ服务器"; <br
} <br
//关闭TCP联结 <br
tcpc.Close(); <br
} <br
<br
</script <br
<html <br
<meta http-equiv="Content-Language" content="zh-cn" <br
<head <br
<title</title <br
</head <br
<body <br
<form runat="server" <br
<table <br
<tr<td align=center colspan=2 <br
<asp:Label id="ICQ_Show" runat="server" ForeColor="red" /</td</tr <br
<tr<td<br</tr <br
<tr<td align=center colspan=2发送ICQ信息</td</tr <br
<tr<td您的ICQ号:</td<td<asp:TextBox id="ICQ_Number" runat="server" /</td</tr <br
<tr<td您的网名:</td<td<asp:TextBox id="ICQ_Name" runat="server" /</td</tr <br