Visual Basic.NET, an example of using HTTPWebRequest object
Posted by Daniel - 736 Views
On the other article which you can view it here, I had described how to use the WebClient object to download resources from the internet. But you do not have enough control with the WebClient if you need to do something more. This time we’re going explore the other more flexible object related to the internet download process.
This object called HttpWebRequest. It’s located under the System.Net namespace. With this object you will have more control over the process, such as the HTTPVersion and the KeepAlive property.
I am not good in describing things, especially in English, so lets get to the point. Below is an example procedure called GetImageData() . This procedure will try to download images from the internet based on the suplied URL.
Dim myHttpWebRequest As HttpWebRequest
Dim ImageData As Bitmap
Dim strSavePath As String = “downloadedimg.jpg”
Try
myHttpWebRequest = CType(WebRequest.Create(strURL), HttpWebRequest)
myHttpWebRequest.KeepAlive = False
myHttpWebRequest.ProtocolVersion = HttpVersion.Version10
If Trim(strURL) <> “” Then
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
ImageData = New Bitmap(Image.FromStream(myHttpWebResponse.GetResponseStream))
ImageData.Save(strSavePath, System.Drawing.Imaging.ImageFormat.Jpeg)
ImageData.Dispose()
myHttpWebResponse.Close()
End If
Catch e As Exception
MsgBox(“ERROR: “ & e.Message)
Finally
End Try
End Sub
Demo project is included, but it’s different with the example procedure above since I use Thread in this demo project. Do not worry, its a simple one.
Download Demo Project (72 KB)
__________________________
The following posts are programmatically considered as related to the current post by YARPP Plugin:
- Downloading file and extracting ZIP compressed file with Visual Basic.NET
- Replacing and filtering text with regular expression using Delphi, Visual Basic and ASP
- Visual Basic Version of ASCII-to-PDU and PDU-to-ASCII Converter Functions
- Passing arguments to your VB.NET console application
- Resizing image on the fly with ASP.NET using the System.Drawing namespace
Related posts brought to you by Yet Another Related Posts Plugin.
Latest from Programming
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
- SmartImageResizer Plugin, WordPress plugin based on Joe Lencioni’s Smart Image Resizer
- Resize Image or Crop Image with Joe Lencioni’s Smart Image Resizer, WordPress Setup
- Free Softwares to help you learn Regular Expression or to enhance your RegEx skill
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
Leave a Reply
Latest Blog Entries
- Sweet Home 3D, a free home design software
- 26x Optical Zoom on a Compact Digital Camera?
- Windows 7 Release Candidate is now available
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
- The Lack of Chances is the Source of Poverty, Can we make a different?
- SmartFTP Client is no longer Free. What would be the best replacement for it?
- Kantaris Media Player, The most suitable Free Media Player on my Audio Environment
Categories
Neighbours and Friends
- Anti Teori
- Busby SEO Test Page
- Deny Sri
- Digital Media Convert
- Freeware Maniac
- Oeroek
- RidhoCyber
- Suraja Web
Comments - Thanks Guys :)
Therese Lachance: Hi, Any idea how to have ContuttoPDF fetch the correct page language?
Marlena Albu: Super Blog, Dude! I am constantly on the watch for new and interesting sites and postings about audio equipment… which is what...
tresloukadu: yo how did u fixed when the tags shows <? and it shows < “& l t ; ” ?? please send me an email.
Sean: This is a great piece of code and thanks for adding the updates. Sean’s last blog post: Not All Text Message Marketing Is Created...
rodhy: Thank for your code, it very usefull for me. best regard.
Most Popular Entries
- Passing arguments to your VB.NET console application
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
- ASCII To PDU Converter (Convert ASCII to PDU and vice versa)
- An example: Using CPort Delphi Component to read data from your cellphone
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
Software Collections
- Sweet Home 3D, a free home design software
- SmartFTP Client is no longer Free. What would be the best replacement for it?
- Kantaris Media Player, The most suitable Free Media Player on my Audio Environment
- TCPView for Windows, Tool to check TCP and UDP Connections on your system
- The Code Snippet Plugin, my favourite syntax highlighter plugin for WordPress
Blogging Related Stuff
- Change the WordPress permalink structure to the best format, and yes it’s a little bit scary :D
- Something is wrong, the Google Search Result from my blog looks bad, don’t laugh please :D
- Several tips to reduce Blog Noise, especially when your blog covers more than one niche
- How to remove your indexed pages or even your entire site from Google and Yahoo!

















