我正在使用以下代码进行共享点身份验证。它在本地机器上工作得很好,但是当我在服务器上部署这个包时,它给出了 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;
}
}
}