Fork me on GitHub

在设置代理的环境下使用SharePoint CSOM

 

SharePoint 的CSOM都是通过HttpRequest来实现和SharePoint服务器的交互的,那么我们如何设置HttpWebRequest的一些特性呢,如Cookie,WebProxy?

 

static void Main(string[] args)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback = (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) => true;
            ClientContext context = new ClientContext(https://domain.sharepoint.com);

            SecureString se = new SecureString();
            foreach (var cc in "password")
            {
                se.AppendChar(cc);
            }

            context.Credentials = new SharePointOnlineCredentials("user@domain.onmicrosoft.com", se);

            context.ExecutingWebRequest += context_ExecutingWebRequest;

            context.ExecuteQuery();

        }

        static void context_ExecutingWebRequest(object sender, WebRequestEventArgs e)
        {
            //e.WebRequestExecutor.WebRequest.Proxy = new System.Net.WebProxy("");
            //e.WebRequestExecutor.WebRequest.CookieContainer= cookie
        }

  通过ExecutingWebRequest 这个事件来定义httpWebRequest的一些行为

posted @ 2015-08-06 17:04  独上高楼  阅读(635)  评论(0编辑  收藏  举报