Most of the equivalent functionality is in the System.Web namespace:
The System.Web namespace provides classes and interfaces that provide interaction between the browser and the server. This namespace includes the HttpRequest class, which provides extensive information about the current HTTP request; The HttpResponse class, which controls the HTTP output to the client; and the HttpServerUtility class, which provides access to server-side utilities and processes. System.Web also includes classes for manipulating cookies, passing files, exception information, and managing the output cache.
A close cousin urlopenis the System.Net.Webclient class:
Provides common methods for sending data and retrieving data from a resource identified by a URI.
using System;
using System.Net;
using System.IO;
public class Test
{
public static void Main (string[] args)
{
if (args == null || args.Length == 0)
{
throw new ApplicationException ("Specify the URI of the resource to retrieve.");
}
WebClient client = new WebClient ();
client.Headers.Add ("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Stream data = client.OpenRead (args[0]);
StreamReader reader = new StreamReader (data);
string s = reader.ReadToEnd ();
Console.WriteLine (s);
data.Close ();
reader.Close ();
}
}
gimel source
share