Go Home

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

通过老婆才知道O2网站上可以发短信,但是需要登陆之类,也不是很方便。。。
反正这几天也没事。。就用c#写了一个通过O2网站发短信的小东西。由于没怎么想,直接写的,代码就乱得不敢恭维了。但是功能基本没什么问题。。目前实现的也就发短信,包括群发。用户组发送还没写,,懒得写了。
 

主要思路就是用HttpWebResponse 还有 HttpWebRequest

和网站的通信也就是几个连接+几个参数而已。通过cv很容易看到他们的完整连接。配置文件都是自己写的,本来想用xml,觉得太麻烦了。就自己写了一个读Tag得

 

 1public bool login(string user, string password)
 2        {
 3            try
 4            {
 5                string loginStr = rt.getValue("Login");
 6                byte[] buf = new byte[38192];
 7                string content = "";
 8                int count = 0;
 9
10                loginStr = loginStr.Replace("[USER]", user);
11                loginStr = loginStr.Replace("[PASSWORD]", password);
12
13                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(loginStr);
14
15                request.Method = "POST";
16                request.KeepAlive = true;
17                request.CookieContainer = cc;
18                request.ContentType = "text/html;charset=ISO-8859-1";
19                request.Timeout = 100000;
20
21
22                //**************************
23                this.process = ConnToServer;
24
25                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
26                Stream resStream = response.GetResponseStream();
27
28                while ((count = resStream.Read(buf, 0, buf.Length)) > 0)
29                {
30                    content += Encoding.Default.GetString(buf, 0, count);
31
32                    //**************************
33                    this.process = ReadFromServer;
34                }

35
36
37                if (content.Contains("Welcome"&& !content.Contains("un-successful"))
38                {
39
40                    /*Get credit balanch information from server*/
41                    this.SetCreditBalance(content);
43
44
45                    this.GetWebTextInfo();
46                    //**************************
47                    this.process = LoginSucc;
48
49                    return true;
50                }

51
52
53
54                resStream.Close();
55                resStream.Dispose();
56
57
58
59                //**************************
60                this.process = LoginFail;
61
62                return false;
63            }

64            catch (Exception e)
65            {
66                Console.WriteLine(e);
67            }

68
69
70            //**************************
71            this.process = LoginFail;
72
73            return false;
74        }



登陆的思路其实是非常简单的。
异步都是在界面里面实现。

2 



3 


1 


posted on 2006-07-11 00:29  Bluagle  阅读(325)  评论(0)    收藏  举报