當前位置: 首頁>>代碼示例>>C#>>正文


C# FileWebResponse.GetResponseStream方法代碼示例

本文整理匯總了C#中System.Net.FileWebResponse.GetResponseStream方法的典型用法代碼示例。如果您正苦於以下問題:C# FileWebResponse.GetResponseStream方法的具體用法?C# FileWebResponse.GetResponseStream怎麽用?C# FileWebResponse.GetResponseStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。


在下文中一共展示了FileWebResponse.GetResponseStream方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Uri

Uri fileUrl = new Uri("file://"+url);
        // Create a 'FileWebrequest' object with the specified Uri. 
        FileWebRequest myFileWebRequest = (FileWebRequest)WebRequest.Create(fileUrl);
        // Send the 'FileWebRequest' object and wait for response. 
        FileWebResponse myFileWebResponse = (FileWebResponse)myFileWebRequest.GetResponse();
                    
        // Get the stream object associated with the response object.
        Stream receiveStream = myFileWebResponse.GetResponseStream();
        
        Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
        // Pipe the stream to a higher level stream reader with the required encoding format. 
        StreamReader readStream = new StreamReader( receiveStream, encode );
        Console.WriteLine("\r\nResponse stream received");

        Char[] read = new Char[256];
        // Read 256 characters at a time.    
        int count = readStream.Read( read, 0, 256 );
        Console.WriteLine("File Data...\r\n");
        while (count > 0) 
        {
            // Dump the 256 characters on a string and display the string onto the console.
            String str = new String(read, 0, count);
            Console.Write(str);
            count = readStream.Read(read, 0, 256);
        }
        Console.WriteLine("");
        // Release resources of stream object.
        readStream.Close();
        // Release resources of response object.
        myFileWebResponse.Close();
開發者ID:.NET開發者,項目名稱:System.Net,代碼行數:30,代碼來源:FileWebResponse.GetResponseStream


注:本文中的System.Net.FileWebResponse.GetResponseStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。