ASP.NET发送ICQ消息DIY

<br> 
<br> 
<br> 
  这里我给大家提供一个很实用的例子,就是在线发送ICQ信息。想一想我们在网页上直接给朋友发送ICQ信息,那是多么美妙的事情啊。呵呵,在吹牛啊,其实ICQ本来就有在线发送的代码,不过,这些都是AOL给你写好的代码,多没有意思啊。还是自已写的比较好,呵呵,废话少说,大家来看代码吧<br> 
<br> 
<% @ Page Language=&quot;C#&quot; %><br> 
<% @ Assembly Name=&quot;System.Net&quot; %><br> 
<% @ Import Namespace=&quot;System.Net&quot; %><br> 
<% @ Import Namespace=&quot;System.Net.Sockets&quot; %><br> 
<% @ Import Namespace=&quot;System.IO&quot; %><br> 
<% @ Import Namespace=&quot;System.Text&quot; %><br> 
<br> 
<Script Language=&quot;C#&quot; Runat=&quot;Server&quot;><br> 
public void Page_Load(Object src,EventArgs e)<br> 
{<br> 
ICQ_Show.Text=&quot;如果提交后,在这里显示信息&quot;; <br> 
}<br> 
<br> 
public void Send_Click(Object sender,EventArgs e)<br> 
{<br> 
string sendmsg;<br> 
string commandmsg;<br> 
file://首先取得要发送的信息<br> 
commandmsg = &quot;from=&quot;+ICQ_Name.Text+&quot;&fromemail=&quot;+ICQ_Email.Text+&quot;&subject=&quot;; <br> 
commandmsg += ICQ_Subject.Text+&quot;&body=&quot;+ICQ_Message.Text+&quot;&to=&quot;+ICQ_Number.Text <br> 
commandmsg += &quot;&Send=Send+Message&quot;;<br> 
file://然后就是组装全部的信息<br> 
sendmsg=&quot;POST /scripts/WWPMsg.dll HTTP/1.1\r\n&quot;;<br> 
sendmsg += &quot;Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,&quot;;<br> 
sendmsg += &quot; application/vnd.ms-excel,&quot;;<br> 
sendmsg += &quot; application/msword, application/vnd.ms-powerpoint, */*\r\n&quot;;<br> 
sendmsg += &quot;Accept-Language: zh-cn\r\n&quot;;<br> 
sendmsg += &quot;Content-Type: application/x-www-form-urlencoded\r\n&quot;;<br> 
sendmsg += &quot;Accept-Encoding: gzip, deflate\r\n&quot;;<br> 
sendmsg += &quot;User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows 95)\r\n&quot;;<br> 
sendmsg += &quot;Host: wwp.icq.com\r\n&quot;;<br> 
sendmsg += &quot;Content-Length: &quot; + commandmsg.Length + &quot;\r\n&quot;;<br> 
sendmsg += &quot;Connection: Keep-Alive\r\n\r\n&quot;;<br> 
sendmsg += commandmsg + &quot;\r\n\r\n&quot;;<br> 
<br> 
Byte[] arrMsg=Encoding.Default.GetBytes(sendmsg.ToCharArray());<br> 
file://需要发送的信息处理完毕<br> 
<br> 
file://======下面就是发送这些信息=====<br> 
file://首先是建立一个TCPClient 对象<br> 
TCPClient tcpc=new TCPClient();<br> 
if(0==tcpc.Connect(&quot;wwp.icq.com&quot;,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(&quot;OK&quot;)!=-1)<br> 
{<br> 
ICQ_Show.Text=&quot;ICQ消息发送成功&quot;;<br> 
}<br> 
else<br> 
{<br> 
ICQ_Show.Text=&quot;ICQ消息发送不成功&quot;;<br> 
}<br> 
<br> 
}<br> 
else<br> 
{<br> 
ICQ_Show.Text=&quot;ICQ消息发送不成功,无法联结ICQ服务器&quot;;<br> 
}<br> 
file://关闭TCP联结<br> 
tcpc.Close();<br> 
}<br> 
<br> 
</script><br> 
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值