What is the best and simplest http user agent in .NET?
I simply want to put in the url have it return the page as a string.
What is the best and simplest http user agent 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.