Return HTTP Response content line by line

Source: Internet
Author: User

 

Preface

Question: 1. What are special characters?

2. Why special characters?

A: special characters refer to symbols that are less frequently used than traditional or commonly used characters and are difficult to directly input, such as mathematical symbols, Unit symbols, and tabs.

Some symbols cannot be directly transmitted in the URL. If you want to pass these special symbols in the URL, you need to use their encoding. The encoding format is % plus the characters' ASCII code, that is, a percent sign %, followed by the corresponding characters' ASCII (hexadecimal) code value. For example, the Space Encoding value is "% 20 ".

 

Problem

How to return HTTP Response content line by line instead of using the entire content as a string

Design

Httpwebrequest. the getresponse () method obtains the HTTP Response stream, transmits the stream to the streamreader () constructor, and then uses streamreader in a while loop. the Readline () method reads data row by row.

Solution

 

 public static void stream() {      Stream st = null;      StreamReader sr = new StreamReader(st);      string line = null;      Console.WriteLine("HTTP Response is line-by-line:");      while((line=sr.ReadLine())!=null)      {          Console.WriteLine(line);      }      st.Close();      sr.Close();            }

I think

Static void main (string [] ARGs) {stream ();} public static void stream () {string url = "www.baidu.com "; // define a byte array byte [] array = encoding. ASCII. getbytes (URL); // assign the array to the data stream memorystream = new memorystream (array); streamreader sr = new streamreader (Stream); // stream ST = NULL; // streamreader sr = new streamreader (ST); string line = NULL; console. writeline ("HTTP response is line-by-line :"); While (line = Sr. Readline ())! = NULL) {console. writeline (line);} stream. Close (); Sr. Close ();}

 

Annotation

The three basic methods used to send HTTP requests (WebClient, webreqest, and httpwebrequest) support returning the associated HTTP responses in the form of stream objects through a certain method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.