Write a program code to send ICQ message with asp.net

Source: Internet
Author: User
Tags object getstream connect sendmsg
Asp.net| program Here I give you a very practical example, is to send ICQ information online. Think about how wonderful it is for us to send ICQ messages directly to our friends on the Web page. Oh, in the boast Ah, in fact, ICQ has been sent online code, but these are AOL to write you a good code, much does not mean AH. Or the self has written better, oh, less nonsense, we look at the code bar.

<% @ 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= "If submitted, show information here";
}

public void Send_click (Object Sender,eventargs e)
{
String sendmsg;
String commandmsg;
Get the information you want to send first
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";
And then assemble all the information.
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-office/9.shtml ' target= ' _blank ' class= ' article ' >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) \ 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 ());
The information that needs to be sent is processed

The following is to send this information =====
The first is to create a TcpClient object
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 message sent successfully";
}
Else
{
icq_show.text= "ICQ message sent unsuccessfully";
}
}
Else
{
icq_show.text= "ICQ Message delivery is not successful, can not connect the ICQ server";
}
Turn off TCP connections
Tcpc. Close ();
}

</script>
<meta http-equiv= "Content-language" content= "ZH-CN"
<title> </title>
<body>
<form runat= "Server" >
<table>
<tr> <td Align=center colspan=2>
<asp:label id= "icq_show" runat= "server" forecolor= "Red"/> </td> </tr>
<tr> <td>
</tr>
<tr> <td align=center colspan=2> send ICQ messages </td> </tr>
<tr> <td> your ICQ: </td> <td> <asp:textbox id= "Icq_number" runat= "Server"/> </td> </tr>
<tr> <td> Your network name: </td> <td> <asp:textbox id= "icq_name" runat= "Server"/> </td> </tr>
<tr> <td> your Email: </td> <td> <asp:textbox id= "Icq_email" runat= "Server"/> </td> </tr>
<tr> <td> Send a topic: </td> <td> <asp:textbox id= "Icq_subject" runat= "Server"/> </td> </tr>
<tr> <td> Send content: </td> <td> <asp:textbox id= "icq_message" runat= "Server"/> </td> </tr>
<tr> <td> <asp:button text= "send ICQ message" runat= "Server"/> </td> </tr>
</table>
</form>

</body>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.