.net framework 具有分层、可扩展和托管的网络服务实现。您可以轻松地将它们集成到您的应用程序中。使用system.net;命名空间。
让我们看看如何访问 uri 类:在 c# 中,它提供统一资源标识符 (uri) 的对象表示 -
uri uri = new uri("http://www.example.com/");webrequest w = webrequest.create(uri);
现在让我们看看 system.net 类。这用于使用安全套接字层 (ssl) 来加密连接。如果 uri 以“https:”开头,则使用 ssl;如果 uri 以“http:”开头,则使用未加密的连接。
以下是示例。对于使用 ftp 的 ssl,请在调用 getresponse() 方法之前将 enablessl 属性设置为 true。
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;
以下示例显示了 system.net 命名空间的使用以及使用 dns.gethostentry、dns.gethostname 方法和 iphostentry 属性 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(); }}
以上就是c# 中的网络的详细内容。