0
votes

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?

1
You can describe better what to try to achieve and the from/to. You are on the same domain of sharepoint ? Is Office 365 or on-premises ? Which type of auth Kerberos or NTLM ?Max
I am outside SharePoint premises, want to access via mobile app. I want to access SharePoint List anonymously.BASEER HAIDER JAFRI
You must setup Sharepoint for anonymous users, otherwise instead of request.Credentials you must supply valid credentialsMax
I have given Read Rights to my list and my website but still I am getting Unauthorized issue. Is there anything that I am missing related to SharePoint permissions and settings?BASEER HAIDER JAFRI
You must pass valid credential to sharepoint: request.Credentials = new NetworkCredentials("user", "pass", "domain") or something like thatMax

1 Answers

1
votes

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/