Search code examples
c#restsharepointsharepoint-2013sharepoint-designer

Get Sharepoint 2013 List using REST API


I want to get List from Sharepoint using mobile devices therefore I am using REST API with DefaultCredentials,I have already given Read rights to my List but I am getting The remote server returned an error: (401) Unauthorized

My Code Is:

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("ListUrl");
request.Method = "GET";
request.Accept = "application/json;odata=verbose";
request.ContentType = "application/json;odata=verbose";
request.UseDefaultCredentials = true;
request.PreAuthenticate = true;
request.Credentials = System.Net.CredentialCache.DefaultCredentials;

Is this possible via REST API or is there any other solution? Is there anything that I am missing?


Solution

  • By default, the REST API is restricted to authenticated users, so you must configure it to anonymous users. You should upload a query properties template on your site collection's root as described on Mastykarz's post:

    http://blog.mastykarz.nl/configuring-sharepoint-2013-search-rest-api-anonymous-users/