HTTP Request Headers in VB.NET

I am attempting to integrate Google Shard contacts with an ASP.NET application. I have successfully implemented the first part of their procedure which is to authenticate the application with the Google account using the code below:


<script runat="server">

Dim t As String

Sub Page_Load(Sender As Object, E As EventArgs)

      t = Request.QueryString("token")
      Dim googleRequest = HttpWebRequest.Create("")
      googleRequest.Method = "GET"
      googleRequest.Headers.Set("Authorization", "AuthSub token=""" & t & """")
      Dim googleResponse = googleRequest.GetResponse()
      outputLabel.Text = googleResponse.toString()
End Sub



The problem I now have is accessing the content of the "googleRequest.GetResponse()" method.

Please note that I am not necessarily looking for a "Google-specific" answer here (but please feel free to give one) but really an explanation of how to extract the data returned inside the "GetResponse()" method of the HttpWebRequest.

NB: I know it's hard but please do not come back with comments like, "you need to do it in jsp or c# etc!" I am looking for a solution please.
Who is Participating?
Dennis AriesConnect With a Mentor CEO @ Arkro ITCommented:
In the Headers-property of the WebResponse (which is returned by the GetResponse), you will find the basic headers, telling you wether the call has been succeeded.

After that, you can use  WebResponse.GetResponseStream() and a StreamReader to read all the data from that stream.

Check link above for a small example.

The string that you read (dumped on the standard output in the example) can be used for your pleasure.

Dim sb = new StringBuilder()
Dim googleResponse = googleRequest.GetResponse()
Dim ReceiveStream As Stream = myWebResponse.GetResponseStream()
Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim readStream As New StreamReader(ReceiveStream, encode)
Dim read(256) As [Char]

Dim count As Integer = readStream.Read(read, 0, 256)
While count > 0
    Dim str As New [String](read, 0, count)
    count = readStream.Read(read, 0, 256)
End While

outputLabel.Text = sb.ToString()

Open in new window

Alfred A.Connect With a Mentor Commented:

Check the sample VB.NET code in the link below.  I believe this is what you are looking for.  It gets the response for the request.
courtthreeAuthor Commented:

With the help of you two guys, I have progressed further with this in 12 hours than I have in two weeks.

@djjaries, the code you supplied has beautifully returned the session token as a string in the following format (Modified for secuity):


Do you (or anyone) have any experience of now using that to access the Google Shared Contacts Feed?
Dennis AriesCEO @ Arkro ITCommented:
You're welcome. I think think the links provided by Alfred1 will help you further.
All Courses

From novice to tech pro — start learning today.