ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash




ASP.NET version of "HTTP Request"


When compared to an http script written in standard ASP, this script really illustrates how important a role objects play in the new .NET framework. It seems like every object returns an object, and while it may take some getting used to, it really does seem to make more sense.

That being said... it'll take a while to get used to! ;)

Here's a zip file of the code (1.1 KB).

Play with the running version.

View the live source code.


I recently (Jan. 16, 2002) got an interesting note about this sample from one of our readers and I thought that I should share it with everyone:

Hi John,

I'm writting in regards to your article at http://www.asp101.com/samples/http.asp ~ June 2001?

I forget how I fell upon it just now and I'm sure you've long since forgotten the code, but it did remind me of how, looking forward as I am to .net and, likely, C#, I'll miss VB's with statement...

One glance at (hopefully hotmail will preserve the formatting)...

Function GetWebPageAsStringShort(strURI As String) As String
	Dim objURI As URI = New URI(strURI)
	Dim objWebRequest As WebRequest = WebRequest.Create(objURI)
	Dim objWebResponse As WebResponse = objWebRequest.GetResponse()
	Dim objStream As Stream = objWebResponse.GetResponseStream()
	Dim objStreamReader As StreamReader = New StreamReader(objStream)
	Dim strHTML As String = objStreamReader.ReadToEnd

	GetWebPageAsStringShort = strHTML
End Function

...and I couldn't resist whipping up...

Function GetWebPageAsStringShort2(strURI As String) As String
	With WebRequest.Create(New URI(strURI)).GetResponse()
	    With New StreamReader(.GetResponseStream())
			GetWebPageAsStringShort2 = .ReadToEnd()
	    End With
	End With
End Function

Admittedly, I'm partial to my version, but I particularly like how the use of the with statement results in a fn that introduces a reader to only two new tokens, the names of the fn and its arg. To be certain, I'm not sure of the details of .net memory management, but, I believe this version is at least as prudent an implementation since the compiler can early-bind with references, perhaps more so as I also create and leave what I can on the stack.

The manner in which indentation in conjunction with progressively shorter lines of code focuses the eye gradually towards the end result is an especially neat side effect. (Yes, I studied visual arts prior to cs ;~)

Of course, it is but one of so many bits of code we'll write in a lifetime. And, I've spent more time writting this email than the fn!

What do you think?

Take Care,
JT from Boston, MA.


Back to the "HTTP Request" sample


Samples

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES