LiveExtract.cs
资源名称:GetFriend.rar [点击查看]
上传用户:asz878
上传日期:2020-04-01
资源大小:189k
文件大小:3k
源码类别:
WEB邮件程序
开发平台:
Visual C++
- /*
- * 作者:方宏俊
- * 日期:2008-10-23
- * 描述:获取 MSN Live 好友列表
- * * */
- using System;
- using System.Collections.Generic;
- using System.Net;
- using System.Text;
- using System.Xml;
- namespace Fhz.Msn.OpenContactsNet
- {
- /// <summary>
- /// MSN Live 提取类
- /// </summary>
- public class LiveExtract : IMailContactExtract
- {
- #region IMailContactExtract Members
- public bool Extract( NetworkCredential credential, out MailContactList list )
- {
- list = new MailContactList();
- bool result = false;
- try
- {
- TicketAcquirer ticketAcquirer = new TicketAcquirer();
- string ticket = ticketAcquirer.GetTicket( credential );
- if ( string.IsNullOrEmpty( ticket ) )
- {
- return false;
- }
- UriBuilder urib = new UriBuilder();
- urib.Scheme = "HTTPS";
- urib.Path = string.Format( "/{0}/LiveContacts", credential.UserName );
- urib.Host = "cumulus.services.live.com";
- urib.Port = 443;
- HttpWebRequest request = ( HttpWebRequest ) WebRequest.Create( urib.Uri );
- string authHeader = string.Format( "WLID1.0 t="{0}"", ticket );
- request.Headers.Add( "Authorization", authHeader );
- WebResponse response = request.GetResponse();
- if ( response.ContentLength != 0 )
- {
- XmlDocument xmlDocument = new XmlDocument();
- xmlDocument.Load( response.GetResponseStream() );
- XmlNodeList contacts = xmlDocument.SelectNodes( "/LiveContacts/Contacts/Contact" );
- foreach ( XmlNode node in contacts )
- {
- XmlNode firstName = node.SelectSingleNode("Profiles/Personal/DisplayName");
- XmlNode firstMail = node.SelectSingleNode("Emails/Email/Address");
- MailContact mailContact = new MailContact();
- mailContact.Name = string.Format( "{0}", firstName.InnerText);
- mailContact.Email = firstMail == null ? string.Empty : firstMail.InnerText;
- list.Add( mailContact );
- }
- }
- result = true;
- }
- catch(Exception ex)
- {
- string a = ex.Message;
- return false;
- }
- return result;
- }
- #endregion
- }
- }