The remote server returned an error 401 unauthorized in SharePoint 2013
Solution:
System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext =
((System.Security.Principal.WindowsIdentity)Thread.CurrentPrincipal.Identity).Impersonate();
System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext =
((System.Security.Principal.WindowsIdentity)Thread.CurrentPrincipal.Identity).Impersonate();
impersonationContext.Undo();