用ASP.Net写一个发送ICQ信息的程序
2024-07-10 12:58:07
供稿:网友
这里我给大家提供一个很实用的例子,就是在线发送icq信息。想一想我们在网页上直接给朋友发送icq信息,那是多么美妙的事情啊。呵呵,在吹牛啊,其实icq本来就有在线发送的代码,不过,这些都是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;
//首先取得要发送的信息
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";
//然后就是组装全部的信息
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());
//需要发送的信息处理完毕
//======下面就是发送这些信息=====
//首先是建立一个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消息发送成功";
}
else
{
icq_show.text="icq消息发送不成功";
}
}
else
{
icq_show.text="icq消息发送不成功,无法联结icq服务器";
}
//关闭tcp联结
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>发送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>发送主题:</td><td><asp:textbox id="icq_subject" runat="server" /></td></tr>
<tr><td>发送内容:</td><td><asp:textbox id="icq_message" runat="server" /></td></tr>
<tr><td><asp:button onclick="send_click" text="发送icq信息" runat="server" /></td></tr>
</table>
</form>
</body>
</html>
,欢迎访问网页设计爱好者web开发。