The following code works in a console application but returns a 401 error from a workflow code activity. The aim is to download and process a .eml file from a Sharepoint 2013 document library. SP and WF both reside on the same server.
System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() at ActivityLibrary2.CodeActivity1.Execute(CodeActivityContext context)
WebRequest request = WebRequest.Create(Url);
request.UseDefaultCredentials = true;
request.PreAuthenticate = true;
request.Credentials = CredentialCache.DefaultCredentials;
WebResponse response = (WebResponse)request.GetResponse();
I've also tried DefaultNetworkCredentials, specifying credentials, same result. The workflow app pool account has full access to the site.
Is there a better approach?