新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论.NET,C#,ASP,VB技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区计算机技术与应用『 Dot NET,C#,ASP,VB 』 → C#快餐-10 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 2227 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: C#快餐-10 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     admin 帅哥哟,离线,有人找我吗?
      
      
      
      威望:9
      头衔:W3China站长
      等级:计算机硕士学位(管理员)
      文章:5255
      积分:18406
      门派:W3CHINA.ORG
      注册:2003/10/5

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给admin发送一个短消息 把admin加入好友 查看admin的个人资料 搜索admin在『 Dot NET,C#,ASP,VB 』的所有贴子 点击这里发送电邮给admin  访问admin的主页 引用回复这个贴子 回复这个贴子 查看admin的博客楼主
    发贴心情 C#快餐-10


    发信人: nice (春天), 信区: DotNET        
    标  题: C#快餐-10
    发信站: BBS 水木清华站 (Thu Jul 26 02:13:25 2001)

    Lesson 10. Simple Internet Programming

        The internet programming is very complex. There are many different  
    conflicting protocols and the older technology conflicts with  a newer one.  
    The idea of .Net is to make the internet more streamlined. Streamlining  
    requires a uniform standard of web publishing. This standard would require  
    web sites (servers) to provide extensive services for the users (clients).  
    The internet then would become something like a huge operating system.  
    I think that Microsoft has a very good idea and that the development of .Net  
    will make the Internet more functional. However, I would like to separate  
    technical issues from PR campaign since the latter tend to get out of control.  
    The time will show whether or not Microsoft will succeed in making the  
    Internet a better (and more profitable for Microsoft) place. I will start with  
    a simple program that translates Domain Name into IP address.

      System.Net namespace is an interface for internet protocols which are  
    currently supported by .Net. System.Net contains classes Dns, IPAddress,
    IPHostEntry. Let me start with the class Dns. It provides simple domain name
    resolution. Some of Dns 's methods are:

    GetHostByAddr(hostname_string ) Creates an IPHostEntry instance from an IP  
    dotted address. For example hostname_string=111.222.32

    GetHostByName(hostname_string) Retrieves the IPHostEntry information  
    corresponding to the Domain name provided in the host parameter.

    GetHostName(void ) Gets the host name of the local machine.
    InetAddr(ip_address_string) Converts an IP address string to an IPAddress  
    instance.

    Resolve(hostname_string) Translates a hostname to an IPAddress instance.

          The program uses method DNS.GetHostByName to create an IPHostEntry.
    Methods of IPAddress has not yet been published by Microsoft at the time of  
    this writing. For the purposes of this lesson we will  treat IPHostEntry as  
    a black box.


    using System;
    using System.Net;
    class IP
    {
        IPAddress [] address;
        public void resolve (string host )
       {
          IPHostEntry entry = Dns.GetHostByName (host);
          address = entry.AddressList;
       }
        public void show_address()
       {
           for( int i = 0; i < address.Length; i++)
          Console.Write (address [i]);
       }
    }
    class Test
    {
       public static void Main()
       {
          IP test = new IP ();
          string input = Console.ReadLine ();
          test.resolve (input);
          test.show_address ();
       }
    }

    Here is another simple program. The program treats a web page as a string of
    text and reads it character by character until it encounters the end of  
    page marker. Domain names need to be provided on command line in a complete  
    form. For example to access ABC you would type http://www.abc.com/.The  
    WebRequest and WebResponse are base classes  used to acces data from the  
    Internet.  

    The C# application works with instances of the WebRequest and WebResponse.  
    The details of the request/response interaction  are carried out by protocol
    -specific descendent classes. WebRequest.GetResponse() returns the response  
    to the Internet request. WebRequestFactory creates WebRequestobjects for spe
    cific network request schemes. The  program bellow also  illustrates usage  
    of Input/Output library provided by System.Net namespace

    using System;
    using System.Net;
    using System.IO;
    public class Test
    {
       public static void Main ()
       {
          string url_string = Console.ReadLine ();
          //make WebRequest to abc's URL
          WebRequest myRequest = WebRequest.Create (url_string);
          //store the response in myResponse
          WebResponse myResponse = myRequest.GetResponse();
          //register I/O stream associated with myResponse
          Stream myStream = myResponse.GetResponseStream ();
          //create StreamReader that reads characters one at a time
          StreamReader myReader = new StreamReader (myStream);
          string s = myReader.ReadToEnd ();
          Console.WriteLine (s); //keep reading till the end of the stream
       }
    }

       There is absolutely no error checking in this program. I have left out  
    exception handling for two reasons. First, to keep the program as simple  
    as possible. Second, to illustrate huge differences between implementations  
    of different websites. Web sites like http://xxx.lanl.govdeny this type of  
    access.  

    While http://www.cbs.comgenerates a large number of (JavaScript?) errors.

    --

    ※ 修改:·walts 於 Jul 26 10:26:38 修改本文·[FROM: 166.111.142.118]
    ※ 来源:·BBS 水木清华站 smth.org·[FROM: 166.111.176.234]
    上一篇
    返回上一页
    回到目录
    回到页首
    下一篇


       收藏   分享  
    顶(0)
      




    ----------------------------------------------

    -----------------------------------------------

    第十二章第一节《用ROR创建面向资源的服务》
    第十二章第二节《用Restlet创建面向资源的服务》
    第三章《REST式服务有什么不同》
    InfoQ SOA首席编辑胡键评《RESTful Web Services中文版》
    [InfoQ文章]解答有关REST的十点疑惑

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2004/11/9 2:25:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Dot NET,C#,ASP,VB 』的所有贴子 点击这里发送电邮给Google AdSense  访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/16 9:03:09

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    2,890.625ms