Solved

HTTP Request Headers in VB.NET

Posted on 2010-11-16
5
1,253 Views
Last Modified: 2013-11-18
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("https://www.google.com/accounts/AuthSubSessionToken")
      googleRequest.Method = "GET"
      googleRequest.Headers.Set("Authorization", "AuthSub token=""" & t & """")
      Dim googleResponse = googleRequest.GetResponse()
      
      outputLabel.Text = googleResponse.toString()
      
End Sub

</script>

---------------------------------------------------

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 vb.net solution please.
0
Comment
Question by:courtthree
  • 2
  • 2
5 Comments
 
LVL 21

Assisted Solution

by:Alfred1
Alfred1 earned 150 total points
ID: 34145114
Hi,

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.

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse.aspx
0
 
LVL 18

Accepted Solution

by:
Dennis Aries earned 350 total points
ID: 34145115
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)
    sb.Append(str)
    count = readStream.Read(read, 0, 256)
End While

readStream.Close()
myWebResponse.Close()
outputLabel.Text = sb.ToString()

Open in new window

0
 
LVL 6

Author Comment

by:courtthree
ID: 34145289
WOW!

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):

Token=1/t__mrBs9xEtKMo*********************IOX5rj1iGN74

Do you (or anyone) have any experience of now using that to access the Google Shared Contacts Feed?
0
 
LVL 21

Expert Comment

by:Alfred1
ID: 34145483
0
 
LVL 18

Expert Comment

by:Dennis Aries
ID: 34145960
You're welcome. I think think the links provided by Alfred1 will help you further.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logiā€¦
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to count occurrences of each item in an array.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now