Library tutorials & articles
Retrieving HTTP content in .NET
Introduction
HTTP content retrieval is an important component for applications these days. Although .NET reduces the need to explicitly retrieve content from the Web through built-in mechanisms in the Web Services framework, ADO.NET and the XML classes, there are still many needs to retrieve Web content directly and manipulate it as text or data downloaded into files. In this article Rick describes the functionality of the HttpWebRequest and HttpWebResponse classes and provides an easy to use wrapper class. The class simplifies the HTTP access and provides most of the common features in an easy to use single interface while still providing full access to the base functionality of the HttpWebRequest class. In the process Rick describes some sticky issues like string encoding and Cookie handling and some related topics like implementing events and running multiple threads to service Web requests.
Last week I decided I needed a good, useful project to throw at .NET to continue my learning curve while actually building something I have a use for. A few years back I'd written a Web Monitoring package that allows me to monitor a set of Web sites and send out alerts when the sites are down and not responding. The app has been showing its age and since it was developed using C++ it has a clunky user interface that's not very maintainable. I thought this would be a good 'training' application to re-build for .NET. This application exercises HTTP functionality built into the .NET Framework, requires setting up and running multiple threads, hooking up events and managing a small set of data without a database backend and finally providing a Windows Form UI. In the future converting this application to work as a Windows service would also be a nice feature. This application is one that lets me explore a wide variety of features of a programming environment. In this month's article I'll describe a few of the features that I needed to build focusing specifically on the HTTP retrieval mechanism.
Related articles
Related discussion
-
True multithread VB source code controls
by Un1 (2 replies)
-
Visual Studio.NET Beta 2 CD
by gringod (2 replies)
-
VB HELP!!!!!!!!!
by CodeWarrior76 (3 replies)
-
EXE Decompiler ?
by James Crowley (6 replies)
-
When is it released?
by outvit (5 replies)
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum) -
Medior/Senior Microsoft .NET Developer
in Randstad en Omstreken (€3K-€4K per month) -
Key Accountmanager
in Noord Holland (€40K-€50K per annum)
Events coming up
-
Oct
14
What’s New in Visual Studio 2008 Service Pack 1?
Birmingham, United Kingdom
“Service Pack? We’re calling it a Service Pack? Are you kidding??!?!” Visual Studio 2008 Service Pack 1 will release later in 2008 alongside .NET Framework V3.5 Service Pack 1 and, together, they represent a significant upgrade to Visual Studio 2008. There are enhancements across many areas of the .NET Framework such as data access, windows application development and web development and there are also corresponding changes in the development environment to support the new framework features.
if (oReqCookie.Name ==
oRespCookie.Name) {
oReqCookie.Value =
oRespCookie.Name;
Do you mean?
if (oReqCookie.Name ==oRespCookie.Name) {
oReqCookie.Value =
oRespCookie.Value;
You have a paragraph that states:
"The most common use of delegates is an eventhandler, which uses the delegate to fire events. When the event publisher fires the event method, the delegate that is assigned to handle the event is called and you're event subscriber object then can simply handle the event by implementing a method in your class."
Unfortunately, for someone trying desparately to learn C#, this sounds like:
"blah blah blah blah blah blah"
I'm sorry but could you publish a REAL SIMPLE example and explanation of asynch calls in Asp.net/C#. I have been all over the web looking for one and they all assume you already know C# so all the delegate calling callback calling method calling delegate calling calling callingcallingcalling.................has just finally gotten on my nerves.
I'm just new to c# coming from VB.NET. This is a great example! Thanks
hi
i have similar problem like you (in a previous time) with in using httwebrequest to login in a website... especially how to handle event clicking ex: onkeypress="checklogin()"
i hope you can help me to solve the problem..
thnx b4
hi
I use httpwebrequest to login into a website (using Networkcrendential). When i got that page i need to click a link. How can we achieve this (axwebbrowser ?) and it contains frames. And also after clicking that menu in second page i have to click a Javascript button. Is there anyway to achieve this.
Rajesh
Your article is very good and your source code is a good start. It has some cool features but is lacking some good programming practices. Most noteable is the lack of finally blocks used. You should try to insure that the Close() method on the WebRequest and WebResponse objects are always closed before the object reference goes out of scope. You can ensure that happens by placing your code in a try/finally block.
Also, you should consider having your class implement the IDisposable interface. And in that implementation clean up, close, and release the resources used by your private variables.