📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Collections;
namespace mmsxx
{
public partial class Form1 : Form
{
// 设置参数
string sMmscUrl = "http://mmsc.monternet.com";
string sProxyUrl = "10.0.0.172:80";
public Form1()
{
InitializeComponent();
}
//private void button1_Click(object sender, EventArgs e)
//{
//}
public void SetMMSC(string szUrl)
{
sMmscUrl = szUrl;
}
public void SetProxy(string szUrl)
{
sProxyUrl = szUrl;
}
/* 发送MMS的过程
1> 创建消息发送接口
MMSender ms = new MMSender();
2> 设置参数属性
默认属性已经是中国移动参数,因此如果是中国移动用户,以下两个操作可以不需要
ms.SetMMSC("http://mmsc.monternet.com");
ms.SetProxy("10.0.0.172:80");
3> 创建消息
MMessage mm= new MMessage();
4> 设置消息内容
mm.SetSubject("标题"); // 设置标题
mm.AddTo("13825271511"); // 添加接收号码,调用一次添加一个接收号码
mm.AddFile("FileName"); // 添加发送文件,包含文件路径,调用一次添加一个发送文件
5> 发送消息
string szReult =ms.Send(mm);
6> 继续发送其他号码
mm.ClearTo();
mm.AddTo("13812345678");
ms.Send(mm);
*/
/* 避免协议冲突的设置
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true"/>
</settings>
</system.net>
</configuration>
*/
public string Send(MMessage mm)
{
try
{
// 验证参数有效性
WebRequest wReq = WebRequest.Create(sMmscUrl);
HttpWebRequest hReq = (HttpWebRequest)wReq;
wReq.Headers.Clear();
if (sProxyUrl.Length > 0)
wReq.Proxy = new WebProxy(sProxyUrl);
wReq.ContentType = "application/vnd.wap.mms-message";
hReq.Accept = "application/vnd.wap.mms-message,text/plain,*/*";
wReq.Method = "POST";
hReq.KeepAlive = false;
hReq.UserAgent = "Nokia6681/2.0 (4.00.15) SymbianOS/8.0 Series60/2.6 Profile/MIDP-2.0 Configuration/CLDC-1.1";
// Write Post Dat
byte[] byMM = mm.GetContent();
hReq.ContentLength = byMM.Length;
Stream sReq = wReq.GetRequestStream();
sReq.Write(byMM, 0, byMM.Length);
sReq.Close();
// Http Request
WebResponse wRes = wReq.GetResponse();
HttpWebResponse hRes = (HttpWebResponse)wRes;
if (hRes.StatusCode == HttpStatusCode.OK)
{
Stream sRes = wRes.GetResponseStream();
StreamReader sr = new StreamReader(sRes);
string szResult = sr.ReadToEnd(); // 发送结果
// Parse result sring
return szResult;
}
}
catch (Exception e)
{
throw new Exception(e.Message);
}
return string.Empty;
}
private void button1_Click(object sender, EventArgs e)
{
/*Form1 ms = new Form1();
ms.SetMMSC("http://mmsc.monternet.com");
ms.SetProxy("10.0.0.172:80");
MMessage mm = new MMessage();
mm.SetSubject("你好Axman!");
mm.SetDeliverTime(6);
mm.AddTo("13842038730");
//mm.AddTo("13702067404");
mm.AddFile("d:\\1.smil");
mm.AddFile("d:\\1.txt");
mm.AddFile("d:\\1.gif");
//mm.AddFile("d:\\mmspackage\\1.mid");
MessageBox.Show(ms.Send(mm));
WebClient wc = new WebClient();
*/
WebRequest wr = (HttpWebRequest)WebRequest.Create("http://www.google.cn");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -