我一直在沙箱 SharePoint 网站中工作,并使用 PnP.Framework 和 Microsoft.SharePointOnline.CSOM 构建我的公司可用于以编程方式管理文件的内容。
下面的代码实际上在前 10 分钟左右的调试中有效,然后开始给我一个 SSL 错误。作为参考,这只是我用来了解 API 的一个控制台应用程序。
代码:
string clientId = "*********";
string redirectUrl = "http://localhost";
string tenantId = "************";
string siteUrl = "https://5klmt2.sharepoint.com/sites/TestTeam";
var authMan = PnP.Framework.AuthenticationManager.CreateWithInteractiveLogin(clientId, redirectUrl, tenantId);
using (ClientContext context = authMan.GetContext(siteUrl))
{
var web = context.Web;
context.Load(web, w => w.Id, w => w.Title);
context.ExecuteQuery();
Console.WriteLine($"{web.Id} - {web.Title}");
var documents = web.GetListByTitle("Documents", l => l.Id, l => l.Title);
Console.WriteLine($"{documents.Id} - {documents.Title}");
}
当它尝试 ExecuteQuery 时它会中断,给我以下错误:
System.Net.WebException
HResult=0x80131620
Message=The SSL connection could not be established, see inner exception.
Source=System.Net.Requests
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at Program.<TestStuff>d__1.MoveNext() in C:\Club Benchmarking\GitHub\SharePointCSOM\SharePointCSOM\Program.cs:line 29
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
Inner Exception 1:
HttpRequestException: The SSL connection could not be established, see inner exception.
Inner Exception 2:
IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
Inner Exception 3:
SocketException: An existing connection was forcibly closed by the remote host.
非常感谢任何帮助:)
尝试使用以下代码绕过证书
HttpClientHandler clientHandler = new HttpClientHandler();
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
// Pass the handler to httpclient(from you are calling api)
HttpClient client = new HttpClient(clientHandler);