开发者

What is the best and simplest http user agent in .NET?

What is the best and simplest http user agent 开发者_JAVA技巧in .NET?

I simply want to put in the url have it return the page as a string.


Thanks to @ion todriel, a suggestion based on System.Net.HttpWebRequest:

using System;
using System.Collections.Generic;
using System.Net;
using System.IO;

namespace myHttpWebRequest
{
    class Program
    {
        static void Main(string[] args)
        {
            var request = HttpWebRequest.Create("http://www.example.com");
            var response = request.GetResponse();
            var reader = new StreamReader(response.GetResponseStream());
            string page = reader.ReadToEnd();
            Console.Write(page);
        }
    }
}

Note the line string page = reader.ReadToEnd (); - return the whole page as a string.

This is not more complicated than the earlier System.Net.WebClinet with an example in the reference document.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜