获取 Email 的通讯录邮箱

最近接到了一项任务,就是要做个类似开心网 SNS 网站邀请好友的功能。

查了一些资料以后,发现更多的是用 PHP 或 java 的例子。 .Net C# 的很少.

参考了他们的例子。自己写了一个. 主要是应用 .Net 的 WebRequest ,HttpWebRequest ,WebResponse , HttpWebResponse 几个类.

个人心得: 登录邮箱各不同,分析路径要耐心。 Http 的间断链接,需要把 HttpHeader 获得后再发回去. 压缩包中有个例子(含源码)。

有兴趣的继续研究的朋友可以Mail我 Dev.guyan # Gmail.com 非诚勿扰

 

PS...    >_<  CSDN 的资源上传总说验证码不对....


贴一段主要的代码

private string GetRequestHtml(string URL, Encoding EnCodeing,ReqMethod RMethod)  
       {  
           string html = string.Empty;  
           try 
           {  
               req = (HttpWebRequest)WebRequest.Create(URL);  
               req.AllowAutoRedirect = true;  
               req.CookieContainer = cookieCon;  
               req.Credentials = CredentialCache.DefaultCredentials;  
               req.Method = RMethod.ToString();  
               req.ContentType = "application/x-www-form-urlencoded";  
               req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; GTB5; Mozilla/4.0(Compatible Mozilla/4.0(Compatible-EmbeddedWB 14.59 http://bsalsa.com/ EmbeddedWB- 14.59  from: http://bsalsa.com/ ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.30729; .NET CLR 3.0.30618; CIBA)";  
 
               res = (HttpWebResponse)req.GetResponse();  
 
               if (cookieheader.Equals(string.Empty))  
               {  
                   cookieheader = req.CookieContainer.GetCookieHeader(new Uri(URL));  
               }  
               else 
               {  
                   req.CookieContainer.SetCookies(new Uri(URL), cookieheader);  
               }  
 
               html= new StreamReader(res.GetResponseStream(), EnCodeing).ReadToEnd();  
           }  
           catch (Exception ex)  
           {  
               html = ex.Message;  
           }  
           return html;  
       } 
 private string GetRequestHtml(string URL, Encoding EnCodeing,ReqMethod RMethod)
        {
            string html = string.Empty;
            try
            {
                req = (HttpWebRequest)WebRequest.Create(URL);
                req.AllowAutoRedirect = true;
                req.CookieContainer = cookieCon;
                req.Credentials = CredentialCache.DefaultCredentials;
                req.Method = RMethod.ToString();
                req.ContentType = "application/x-www-form-urlencoded";
                req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; GTB5; Mozilla/4.0(Compatible Mozilla/4.0(Compatible-EmbeddedWB 14.59 http://bsalsa.com/ EmbeddedWB- 14.59  from: http://bsalsa.com/ ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; InfoPath.2; .NET CLR 3.5.30729; .NET CLR 3.0.30618; CIBA)";

                res = (HttpWebResponse)req.GetResponse();

                if (cookieheader.Equals(string.Empty))
                {
                    cookieheader = req.CookieContainer.GetCookieHeader(new Uri(URL));
                }
                else
                {
                    req.CookieContainer.SetCookies(new Uri(URL), cookieheader);
                }

                html= new StreamReader(res.GetResponseStream(), EnCodeing).ReadToEnd();
            }
            catch (Exception ex)
            {
                html = ex.Message;
            }
            return html;
        }

源代码吗下载: http://www.rssink.com/Temp/GetEmailContacts.rar

 

转自:http://blog.csdn.net/skylen/archive/2009/03/27/4028906.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值