Retrieving cookie info from header

lleemon

Member
Joined
Apr 13, 2006
Messages
7
Programming Experience
3-5
I am using HttpWebRequest to do a POST and then regex the response for a certain part of the html code.

After I get the response how do I view the header information to see what was passed?

VB.NET:
....
objResponse = objRequest.GetResponse()
        srResponse = New StreamReader(objResponse.GetResponseStream(), Encoding.ASCII)
        txtOutput.Text = srResponse.ReadToEnd
        srResponse.Close()
....

Using Fiddler I see the Response Header a few Set-Cookie values. Through code I want to be able to view these and also pass on to the next request.

Thanks.
 
I put this in a button and also have a textbox called txtOutput and a textbox called txtCookie. This seems to work but compairing the cookie to what Fiddler says I only have part of the cookie.

Kind of wondering if it has something to do with redirects that I don't see and this is the final response.

Any HttpWebResponse expert that use Fiddler out there?

VB.NET:
 Dim objRequest As HttpWebRequest
        Dim sRequest As String
        Dim arrRequest As Byte()
        Dim objUTF8Encoding As UTF8Encoding
        Dim strmRequest As Stream
        Dim objResponse As HttpWebResponse
        Dim srResponse As StreamReader

        objRequest = CType(WebRequest.Create("http://www.domain.com"), HttpWebRequest)
        'objRequest.Method = "POST"
        'objRequest.ContentType = "application/x-www-form-urlencoded"

        'Create request body
        'sRequest = ""
        'objUTF8Encoding = New UTF8Encoding()
        'arrRequest = objUTF8Encoding.GetBytes(sRequest)

        'Add body to request
        'objRequest.ContentLength = arrRequest.Length
        'strmRequest = objRequest.GetRequestStream()
        'strmRequest.Write(arrRequest, 0, arrRequest.Length)
        'strmRequest.Close()

        'Get response
        objResponse = objRequest.GetResponse()
        srResponse = New StreamReader(objResponse.GetResponseStream(), Encoding.ASCII)
        txtOutput.Text = srResponse.ReadToEnd
        srResponse.Close()

        If Not objResponse.Headers("Set-Cookie") Is Nothing Then
            txtCookie.Text = objResponse.Headers.Item("Set-Cookie")
        End If
 
Back
Top