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


C# WebResponse.GetResponseStream方法代碼示例

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


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

示例1: StreamReader

// Create a 'WebRequest' object with the specified url. 
 WebRequest myWebRequest = WebRequest.Create("http://www.contoso.com"); 

// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse(); 

// Obtain a 'Stream' object associated with the response object.
Stream ReceiveStream = myWebResponse.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("\nResponse stream received");
 Char[] read = new Char[256];

    // Read 256 charcters at a time.    
 int count = readStream.Read( read, 0, 256 );
    Console.WriteLine("HTML...\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 the resources of stream object.
 readStream.Close();

 // Release the resources of response object.
 myWebResponse.Close();
開發者ID:.NET開發者,項目名稱:System.Net,代碼行數:34,代碼來源:WebResponse.GetResponseStream


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