0

我正在使用以下代码进行共享点身份验证。它在本地机器上工作得很好,但是当我在服务器上部署这个包时,它给出了 401 错误。

class Program
{

    static void Main(string[] args)
    {
        //Delcaring Required variable (Actual variable values have been changed to dummy one)
        var webUri = new Uri("https://blahblah.sharepoint.com");  
        string proxy = "http://abc.abc.com:1234/";
        const string userName = "abc@blahblah.com";
        const string password = "123";
        string SalesPOV_GUID = "6319bd1f-7f-4ffd-95dc-a992afc4da10";
        string Clients_GUID = "ojfoeiawe-3abcc6-41cd-be23-cf6043671d53";

        //Creating a secured sring for SharepointOnline Credentials
        var securePassword = new SecureString();
        foreach (var c in password)
        {
            securePassword.AppendChar(c);
        }

        //Setting up credentials for Sharepoint
        var credentials = new SharePointOnlineCredentials(userName, securePassword);

        //Makiing a Call
        using (var client = new WebClient())
        {


            try
            {
                //setting up proxy
                System.Net.WebProxy wp = new System.Net.WebProxy();
                Uri newUri = new Uri(proxy);
                wp.Address = newUri;
                client.Proxy = wp;
            }
            catch (WebException e) //In package we need to fail the package on catching exception.
            {
                string pageContent = new StreamReader(e.Response.GetResponseStream()).ReadToEnd().ToString();
            }
            client.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
            client.Credentials = credentials;
        }
    }
}
4

1 回答 1

0

检查您的共享点网站是否设置为物理路径的“直通”身份验证。

于 2018-11-28T09:20:45.493 回答