YuviSense: Codin Kid

Yuvi, a 17 year old wannabe geek from India.
  • rss
  • Blog
  • Photography
  • Indians on Twitter
  • About Me
  • Contact

[Tech]Finding Size of a HTTP Resource in 4 Lines of VB.NET Code..

April 10, 2006 | 7:45 pm
Well, my First coding Tech Post. And, Here are the four lines of code that get you just the size of a HTTP Resource, without the content. A HTTP Resource is just any file which is available over HTTP.

Dim wr As Net.HTTPWebRequest = _
Net.HTTPWebRequest.Create("http://yuvipanda.blogspot.com")
wr.Method = "HEAD"
Dim wresp As Net.HTTPWebResponse = wr.GetResponse
MsgBox(wresp.ContentLength / 1024)

That’s it! Running it would give you the size of my Blog Home Page in Kilobytes. Here’s a rundown of each line of code:

Line 1: I create a HTTPWebRequest object that points to the http://yuvipanda.blogspot.com page.

Line 2: Most important line. HTTP methods instruct the HTTP server to perform certain actions on the specified Resource. For example, the most common method, GET, just retrieves the given Resource, while the HEAD methods retrieves only the Headers of the response. Headers contain important information about the content of the response being sent back, such as it’s length, type, last modified date, etc.. Also, you can also access all the Headers through the Headers collection of the Headers property of Response.

Line 3: We just send the Request and get the Response for it.

Line 4: We get the ContentLength property of the Response object, which gives the Length of the Resource in Bytes. We divide by 1024 to convert it to Kilobytes. And, use msgbox to display it to the user!

So, It’s simple as that! Learnt it from the HTTP 1.1 Specs, which are quite well written. Get them here. If a worthless 1 5 year old like me can understand them, you too can:D

P.S. I asked Aswin if he knew how to do it, and he gave me a roundabout way of opening a socket, sending a GET request and aborting the socket after you get the Content-Length header. Not the way a VB.NET developer does it:D I’m such a Weasel:D I’m so proud, I beat a great VB.NET Developer….

Categories
Tech
Comments rss
Comments rss
Trackback
Trackback

« 30 mins of pure Horror… This, is how a Program should be… »

2 responses

ha ha!!

Aswin Anand T.H. | April 10, 2006 | 7:48 pm

ha ha!!

btw, who told im great??

Aswin Anand T.H. | April 10, 2006 | 7:49 pm

btw, who told im great??

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Contact Me

Email: yuvipanda@gmail.com
IM: yuvipanda@msn.com
GTalk: yuvipanda

My Photos


View my Flickr Page

My Badge


IndiBlogger - Where Indian Blogs Meet

Archives

  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox