Solved

HTTP Request Headers in VB.NET

Posted on 2010-11-16
5
1,470 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

623 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