Home > Article > Backend Development > Networking in C#
.NET Framework features a layered, extensible, and managed implementation of web services. You can easily integrate them into your application. Use System.Net; namespace.
Let us see how to access the Uri class: In C#, it provides an object representation of a Uniform Resource Identifier (URI) -
Uri uri = new Uri("http://www.example.com/"); WebRequest w = WebRequest.Create(uri);
Now let us see the System.Net class. This is used to encrypt the connection using Secure Sockets Layer (SSL). If the URI begins with "https:", SSL is used; if the URI begins with "http:", an unencrypted connection is used.
The following are examples. For SSL using FTP, set the EnableSsl property to true before calling the GetResponse() method.
String uri = "https://www.example.com/"; WebRequest w = WebRequest.Create(uri); String uriServer = "ftp://ftp.example.com/new.txt" FtpWebRequest r = (FtpWebRequest)WebRequest.Create(uriServer); r.EnableSsl = true; r.Method = WebRequestMethods.Ftp.DeleteFile;
The following example shows the use of the System.Net namespace and the use of the Dns.GetHostEntry, Dns.GetHostName method, and IPHostEntry properties AddressList -
using System; using System.Net; class Program { static void Main() { String hostName = string.Empty; hostName = Dns.GetHostName(); Console.WriteLine("Hostname: "+hostName); IPHostEntry myIP = Dns.GetHostEntry(hostName); IPAddress[] address = myIP.AddressList; for (int i = 0; i < address.Length; i++) { Console.WriteLine("IP Address {1} : ",address[i].ToString()); } Console.ReadLine(); } }
The above is the detailed content of Networking in C#. For more information, please follow other related articles on the PHP Chinese website!