Provides implementation for http request. This class cannot be inherited.
public sealed class HttpRequest: Object, IDisposable
ObjectHttpRequest
// 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;
{
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";
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()
{
Start = new System.Windows.Forms.Button();
Start.Location = new System.Drawing.Point(50, 70);
Start.Click += new EventHandler(start_click);
Abort = new System.Windows.Forms.Button();
Abort.Location = new System.Drawing.Point(150, 70);
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.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.ScrollBars = ScrollBars.Vertical;
Controls.Add(Start);
Controls.Add(Abort);
Controls.Add(Url);
Controls.Add(Displaying);
ResumeLayout(false);
}
void start_click(object obj, EventArgs ea)
{
HttpRequest req = new HttpRequest();
req.StateChanged += new EventHandler(on_state_changed);
}
void abort_click(object obj, EventArgs ea)
{
}
void on_url_changed(object obj, EventArgs ea)
{
Start.Enabled = Url.TextLength > 0 ;
}
static void Main()
{
Application.Run( new MyForm() );
}
}
Namespace System.Net Flash Library System.scl Flash Library Version 2.0.0.1308 Silverlight Library System.Windows.Forms.dll
| © 2003-2007 NETiKA Technologies. All rights reserved. |