GOA - System.Net.HttpRequest

HttpRequest Class


Provides implementation for http request. This class cannot be inherited.

Definition

public sealed class HttpRequest: Object, IDisposable

Members Table

MethodDescription
AbortCancels a request to an url.
AddHeaderAdds the header to request.
Dispose
EqualsOverloaded. Compares two objects to determine if they are equal. (Inherited from Object)
GetHashCodeServes as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table. (Inherited from Object)
GetTypeGets the Type of the current instance. (Inherited from Object)
HttpRequestInitializes a new instance of HttpRequest.
ReferenceEqualsDetermines whether the specified Object instances are the same instance. (Inherited from Object)
StartOverloaded. Starts the request.
ToStringReturns a String that represents the current Object. (Inherited from Object)
PropertyDescription
ContentLengthGets the total size of the response content.
LoadedPercentageGets the loaded percentage of the request.
LoadedSizeGets the size of the response content already loaded.
MethodGets or sets the method for the request.
ResponseGets the response of the request.
SpeedGets the speed of downloading.
StateGets the state of the request.
TimeoutGets or sets the time out for the response.
EventDescription
StateChangedHandles the changes of the state of the request.

Inheritance Hierarchy

Object
HttpRequest

Examples

// This example creates a HttpRequest to the NETiKA page.

// It shows some properties of HttpRequest.

 

using System;

using System.Diagnostics;

using System.Drawing;

using System.Windows.Forms;

using System.Collections;

using System.Collections.Specialized;

using System.Net;

using System.Web;

 

/////////////////////////////////////////////////////////////////////////////

 

public class MyForm: System.Windows.Forms.Form

{

   private System.Windows.Forms.Button Start, Abort;

   private System.Windows.Forms.TextBox Url, Displaying;

   string UrlText;

   private HttpRequest req = null;

 

   public MyForm()

   {

      InitializeComponent();

   }

 

void on_state_changed( object sender, EventArgs e )

{

   HttpRequest req= (HttpRequest) sender;

 

   switch( req.State )

   {

   case HttpRequestState.Error:

   {

      Debug.WriteLine( "HttpRequestState: Error" );

      Displaying.Text = "HttpRequestState: Error " + "\n";

      Debug.Assert(false,"DataLoader failed");

      Displaying.Text += "DataLoader failed" + "\n";

      break;

   }

 

   case HttpRequestState.Success:

   {

      Debug.WriteLine( "HttpRequestState: Success" );

      Displaying.Text += "HttpRequestState: Success" + "\n" ;

      Debug.WriteLine( "Testing Speed " +req.Speed);

      Displaying.Text += "Testing Speed " +req.Speed + "\n";

      HttpRequestResponse response = req.Response;

      Debug.WriteLine( "Content length = " +response.ContentLength );

      Displaying.Text += "Content length = " +response.ContentLength+ "\n";

      Debug.WriteLine( "The name of method " +req.Method);

      Displaying.Text += "The name of method " +req.Method+ "\n";

      Abort.Enabled = false;

      string data= response.Data;

      StringDictionary dict= HttpUtility.DecodeQuery(data);

      foreach( string key in dict.Keys )

      {

         string msg= key + " = '" + dict[key] + "'";

         Debug.WriteLine(msg);

         Displaying.Text += msg + "\n";

      }

      break;

   }

   case HttpRequestState.Running:

   {

      Debug.WriteLine( "The percent of downloading " +req.LoadedPercentage+"%" );

      Debug.WriteLine( "The number of bytes already downloaded " +req.LoadedSize);

      break;

   }

 

   case HttpRequestState.Cancelled:

   {

      Debug.WriteLine( "HttpRequestState: Cancelled" );

      break;

   }

 

   case HttpRequestState.Timeout:

   {

      Debug.WriteLine( "HttpRequestState: Timeout" );

      break;

   }

}

}

 

private void InitializeComponent()

{

   SuspendLayout();

   Start = new System.Windows.Forms.Button();

   Start.Location = new System.Drawing.Point(50, 70);

   Start.Text = "Start";

   Start.Click += new EventHandler(start_click);

 

   Abort = new System.Windows.Forms.Button();

   Abort.Location = new System.Drawing.Point(150, 70);

   Abort.Text = "Abort";

   Abort.Click += new EventHandler(abort_click);

 

   Url= new System.Windows.Forms.TextBox();

   Url.Location= new System.Drawing.Point(Start.Left, Start.Top - 30);

   Url.Size= new Size( Start.Width*3, 20);

   Url.Multiline= true;

   Url.Text= "http://www.netikatech.com/";

   Url.TextChanged += new EventHandler(on_url_changed);

 

   Displaying = new System.Windows.Forms.TextBox();

   Displaying.Location= new System.Drawing.Point(Start.Left, Start.Bottom + 5 );

   Displaying.Size= new Size( Start.Width*6, 200);

   Displaying.Multiline= true;

   Displaying.ScrollBars = ScrollBars.Vertical;

   Displaying.Text= "";

 

   Start.Enabled=true;

   Abort.Enabled= false;

   Controls.Add(Start);

   Controls.Add(Abort);

   Controls.Add(Url);

   Controls.Add(Displaying);

   ResumeLayout(false);

}

 

void start_click(object obj, EventArgs ea)

{

   UrlText = Url.Text;

   HttpRequest req = new HttpRequest();

   req.StateChanged += new EventHandler(on_state_changed);

   req.Start(UrlText );

   Abort.Enabled = true;

}

 

void abort_click(object obj, EventArgs ea)

{

   req.Abort();

}

 

void on_url_changed(object obj, EventArgs ea)

{

   Start.Enabled = Url.TextLength > 0 ;

}

 

static void Main()

{

   Application.Run( new MyForm() );

}

}

Class Information

NamespaceSystem.Net
Flash LibrarySystem.scl
Flash Library Version2.0.0.1308
Silverlight LibrarySystem.Windows.Forms.dll



© 2003-2007 NETiKA Technologies. All rights reserved.