Solved

HTTP Request Headers in VB.NET

Posted on 2010-11-16
5
1,296 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

786 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