请问WebRequestFactory类在哪个命名空间下,为什么我在调试时总说:D:\myjob\gethttp\Form1.cs(122): 找不到类型或命名空间名称“WebRequestFactory”(是否缺少 using 指令或程序集引用?)

解决方案 »

  1.   

    看起来是一个古老的东西,我搜索MSDN,在2001年的MSDN Magazine的代码示例中看到了这个类,代码如下:
    // Create a WebRequest object passing in the desired URI to the .Create() 
    // method and then 
    // get a response from the server by calling .GetResponse();
    WebRequest WReq = WebRequestFactory.Create("http://www.mypeer-to-  
                                               peer.com/news.htm");
    WebResponse WResp = WReq.GetResponse();应该就是现在的WebRequest,看起来是beta版本的产物,后来MS将这两个东西统一了吧。现在的用法:
    // Create a new 'Uri' object with the specified string.
    Uri myUri =new Uri("http://www.contoso.com");
    // Create a new request to the above mentioned URL.    
    WebRequest myWebRequest= WebRequest.Create(myUri);
    // Assign the response object of 'WebRequest' to a 'WebResponse' variable.
    WebResponse myWebResponse= myWebRequest.GetResponse();
      

  2.   

    楼上正解,WebRequestFactory是beta版的东西,现在应该是WebRequest,在System.Net名字空间中。