Read HTML source code

Source: Internet
Author: User
I am a beginner in C #. Today is three days !!! Encountered a problem!

When I read the HTML source code, I found an example and used stream to read it, but the byte cannot be saved. I found another solution:

Byte [] Buf = new byte [1, 1024];
String test = "";
Int COUNT = 0;
Httpwebrequest request = (httpwebrequest) webrequest. Create ("http://www.163.com ");
Httpwebresponse response = (httpwebresponse) request. getresponse ();
Stream resstream = response. getresponsestream ();
While (true)
{
Count = resstream. Read (BUF, 0, Buf. Length );
// Exit the loop after reading.
If (count <= 0)
Break;
// Convert the number of bytes read to a string
Test + = encoding. ASCII. getstring (BUF, 0, count );
}

Now the string test stores the complete HTML, which is recorded !!!

As I am a newbie, I hope you can find a better solution. Don't hesitate to give me some advice !!!

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.