HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.example.com"); request.Credentials = new NetworkCredential("username", "password"); // Make the request
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftp.example.com/file.txt"); request.Credentials = new NetworkCredential("username", "password"); request.Method = WebRequestMethods.Ftp.DownloadFile; // Make the request and download the fileIn this example, the FtpWebRequest instance is created with the URL of the resource to be downloaded. The Credentials property is set to an instance of the NetworkCredential class, which provides the username and password to use for authentication. Package Library: System.Net.Primitives ICredentials interface is a part of the System.Net.Primitives package library. This library provides the primitives that are common across several networking APIs in the .NET Framework, including HTTP, FTP, and SMTP.