这是我之前在 Stackoverflow 中提出的问题之一的后续问题。
我正在尝试使用 HTTPClient 和 Sharepoint 2013 REST API 连接到 Sharepoint Online Premise 以获取“文档库”中的文档。
我在这里所做的只是一个使用 HttpClient 的简单匿名 HTTP GET 调用。
代码如下:
System.Net.Http.HttpClient _Client = new System.Net.Http.HttpClient();
_Client.BaseAddress = new Uri("https://test.sharepoint.com/_vti_bin/ListData.svc");
_Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/atom+xml"));
_Client.DefaultRequestHeaders.Add("auth_user", "test@test.onmicrosoft.com");
_Client.DefaultRequestHeaders.Add("auth_pass", "test");
_Client.DefaultRequestHeaders.Add("Accept", "application/json;odata=verbose");
HttpResponseMessage resp = _Client.GetAsync(new Uri("https://test.sharepoint.com/_vti_bin/ListData.svc/Documents()")).Result;
string respString = resp.Content.ReadAsStringAsync().Result;
我收到以下错误:
无法从传输连接读取数据:连接已关闭。
堆栈跟踪如下:
[IOException: Unable to read data from the transport connection: The connection was closed.]
System.Net.ConnectStream.EndRead(IAsyncResult asyncResult) +6501654
System.Net.Http.WebExceptionWrapperStream.EndRead(IAsyncResult asyncResult) +30
System.Net.Http.StreamToStreamCopy.BufferReadCallback(IAsyncResult ar) +54
[HttpRequestException: Error while copying content to a stream.]
[AggregateException: One or more errors occurred.]
System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) +3569193
System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) +73
System.Threading.Tasks.Task`1.get_Result() +10522673
WebApp.Test.Page_Load(Object sender, EventArgs e) in @Location
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
我浏览了各种博客/文章以获得解决问题的一些想法。但我还没有找到任何解决方案。
对此有什么想法吗?