Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HTTP Request Headers in VB.NET

Posted on 2010-11-16
5
Medium Priority
?
1,608 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:Alfred A.
Alfred A. earned 600 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 1400 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:Alfred A.
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

783 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