title: Sharepoint 2013 REST API call using C#
body: <p>This is a follow-up question to one of <a href="https://stackoverflow.com/questions/19728100/using-the-httpclient-and-sharepoint-2013-rest-apis-to-get-documents">my earlier question</a> in Stackoverflow.</p>
  
  <p>I am trying to connect to Sharepoint Online Premise to get documents in the "Document Library" by using the HTTPClient and the Sharepoint 2013 REST API.</p>
  
  <p>All i am doing here is a Simple Anonymous HTTP GET call using HttpClient.</p>
  
  <p>The code is as follows :</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>And i am getting the following error:</p>
  
  <p>Unable to read data from the transport connection: The connection was closed.</p>
  
  <p>Stack Trace is as follows :</p>
  
  <pre><code>[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
  </code></pre>
  
  <p>I have gone through various <a href="http://dlr2008.wordpress.com/2013/10/31/sharepoint-2013-rest-api-the-c-connection-part-1-using-system-net-http-httpclient/" rel="nofollow noreferrer">blogs/articles</a> to get some idea to solve the issue.But i cudn't find any solution yet.</p>
  
  <p>Any thoughts on this?</p>