How to Send and Receive HTTP Web Request & Response in Vb .Net?

HTTP Request and Response

Paresh
Sending Web Request and getting Web response if one of the basic way of communication with the server. In VB .net it is very easy. These are the steps what you have to follow.

1. Create one project with one Class & Import these two namespaces in your class.

Imports System.Net

Imports System.IO

2. Now in a function where you want to send web HTTP request, write below lines of code

0: Dim webStream As Stream

1: Dim webResponse = ""

2: Dim req As HttpWebRequest

3: Dim res As HttpWebResponse

4: ' REQUEST PAGE (We are requesting Google Finance Page with NSE:RENUKA Stock Info

5: req = WebRequest.Create("http://www.google.com/finance?q=NSE:RENUKA")

6:

7: req.Method = "GET" ' Method of sending HTTP Request(GET/POST)

8: res = req.GetResponse() ' Send Request

9:

10: webStream = res.GetResponseStream() ' Get Response

11: Dim webStreamReader As New StreamReader(webStream)

12: ' READ Response in one Variable

13: While webStreamReader.Peek >= 0

14: webResponse = webStreamReader.ReadToEnd()

15: End While

3. At the end of the line:15 above, in the webResponse variable you will get the whole HTTP response and you can use it to get/retrieve values from that response.

This types of methods can be used if you want to build software which will be taking some values from some sites and displaying in in the Tool. The best example is Desktop Stock Ticker. We can build Real time Stock Ticker just based on it in VB .net.

Published by Paresh

I love to do Painting, Sketching, Photography and many more things. I started writing on things which interests me. I am not an expert in writing but I am trying to be a good writer :) Most of the time yo...  View profile

  • How to send HTTP Request using VB .net
  • How to get HTTP Response using VB .net
  • What can we do using HTTP Request and Response?

To comment, please sign in to your Yahoo! account, or sign up for a new account.