当前位置: 首页>>代码示例>>C#>>正文


C# HttpWebResponse.GetResponseStream方法代码示例

本文整理汇总了C#中System.Net.HttpWebResponse.GetResponseStream方法的典型用法代码示例。如果您正苦于以下问题:C# HttpWebResponse.GetResponseStream方法的具体用法?C# HttpWebResponse.GetResponseStream怎么用?C# HttpWebResponse.GetResponseStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.HttpWebResponse的用法示例。


在下文中一共展示了HttpWebResponse.GetResponseStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StreamReader

// Creates an HttpWebRequest with the specified URL. 
    HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
    // Sends the HttpWebRequest and waits for the response.			
    HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 
    // Gets the stream associated with the response.
    Stream receiveStream = myHttpWebResponse.GetResponseStream();
    Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
    // Pipes 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];
    // Reads 256 characters at a time.    
    int count = readStream.Read( read, 0, 256 );
    Console.WriteLine("HTML...\r\n");
    while (count > 0) 
        {
            // Dumps the 256 characters on a string and displays the string to the console.
            String str = new String(read, 0, count);
            Console.Write(str);
            count = readStream.Read(read, 0, 256);
        }
    Console.WriteLine("");
    // Releases the resources of the response.
    myHttpWebResponse.Close();
    // Releases the resources of the Stream.
    readStream.Close();
开发者ID:.NET开发者,项目名称:System.Net,代码行数:26,代码来源:HttpWebResponse.GetResponseStream

示例2: HttpWebResponse.GetResponseStream()

//引入命名空间
using System;
using System.Net;
using System.IO;

public class WebApp {
    public static void Main() {
        String page = "http://www.yoursite.net/index.html";
        HttpWebRequest site = (HttpWebRequest)WebRequest.Create(page);
        HttpWebResponse response =(HttpWebResponse)site.GetResponse();
        Stream dataStream = response.GetResponseStream();
        StreamReader read = new StreamReader(dataStream);
        String data = read.ReadToEnd();
        Console.WriteLine(data);
    }
}
开发者ID:C#程序员,项目名称:System.Net,代码行数:16,代码来源:HttpWebResponse.GetResponseStream


注:本文中的System.Net.HttpWebResponse.GetResponseStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。