⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysendicqmsg.aspx.cs

📁 ASP C#代码实例 适合初学人士学习使用
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Net;
using System.IO;
using System.Net.Sockets;

namespace Example_11_18
{
	/// <summary>
	/// Summary description for MySendICQMsg.
	/// </summary>
	public class MySendICQMsg : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label ICQ_Show;
		protected System.Web.UI.WebControls.TextBox ICQ_Number;
		protected System.Web.UI.WebControls.TextBox ICQ_Name;
		protected System.Web.UI.WebControls.TextBox ICQ_Email;
		protected System.Web.UI.WebControls.TextBox ICQ_Subject;
		protected System.Web.UI.WebControls.Button SendBtn;
		protected System.Web.UI.WebControls.TextBox ICQ_Message;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			ICQ_Show.Text="如果提交后,在这里显示信息";
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.SendBtn.Click += new System.EventHandler(this.SendBtn_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void SendBtn_Click(object sender, System.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();
			try
			{
				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消息发送不成功";
				}

			}
			catch
			{
				ICQ_Show.Text="ICQ消息发送不成功,无法联结ICQ服务器";
			}
			//关闭TCP联结
			tcpc.Close();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -