Question about VB program results...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    #1

    Question about VB program results...

    I have the following two button click procedures to retrieve html code from
    web sites.

    The code for Button1 seems to work fine. Button2 works fine for
    http://yahoo.com but not for http://groups.google.com. When trying the
    Google site, iContentLength is -1 after it is set to
    myResponse.Cont entLength. Any ideas why? If I uncomment the lines in
    Button2's event handler then that part of it will work with Google's site,
    using the same technique that Button1 uses.

    I'm trying to learn VB while working on this so that's why I'm interested in
    why Button2 works for some sites but not for all...

    It seems like iContentLength = myResponse.Cont entLength doesn't work
    properly. I am not sure how to look at the myResponse stream object using
    the debugger so I don't know how to make heads or tails of this.

    Thanks for any help,

    David


  • David

    #2
    Re: Question about VB program results...

    "David" <davidd31415@yo owhoo.comwrote in message
    news:BqGdnSa5Ou R3XMrbnZ2dnUVZ_ syunZ2d@comcast .com...
    >I have the following two button click procedures to retrieve html code from
    >web sites.
    >
    The code for Button1 seems to work fine. Button2 works fine for
    http://yahoo.com but not for http://groups.google.com. When trying the
    Google site, iContentLength is -1 after it is set to
    myResponse.Cont entLength. Any ideas why? If I uncomment the lines in
    Button2's event handler then that part of it will work with Google's site,
    using the same technique that Button1 uses.
    >
    I'm trying to learn VB while working on this so that's why I'm interested
    in why Button2 works for some sites but not for all...
    >
    It seems like iContentLength = myResponse.Cont entLength doesn't work
    properly. I am not sure how to look at the myResponse stream object using
    the debugger so I don't know how to make heads or tails of this.
    >
    Thanks for any help,
    >
    David
    >
    >
    >
    The code might help a bit...

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    Dim myChar As Char
    Dim myRequest As HttpWebRequest =
    HttpWebRequest. Create(Me.textU RL.Text)
    Dim webResponse As HttpWebResponse = myRequest.GetRe sponse
    Dim responseStream As IO.Stream = webResponse.Get ResponseStream
    Dim responseReader As StreamReader = New
    StreamReader(re sponseStream)
    Dim writer As StreamWriter = New StreamWriter("c :\textStream.tx t",
    Me.ckAppend.Che cked)
    writer.WriteLin e("Dumping HTML stream...")
    Do Until responseReader. EndOfStream = True
    myChar = ChrW(responseRe ader.Read)
    If Asc(myChar) = 10 Then writer.Write(Ch r(13))
    writer.Write(my Char)
    Loop
    writer.Close()
    End Sub
    Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button2.Click
    Dim myRequest As HttpWebRequest =
    HttpWebRequest. Create(Me.textU RL.Text)
    Dim myResponse As HttpWebResponse = myRequest.GetRe sponse
    Dim m_sPageResponde d As String = myResponse.Resp onseUri.ToStrin g
    Dim iContentLength As Integer
    Dim sTotalBuffer() As Byte
    Dim br As New BinaryReader(my Response.GetRes ponseStream)
    Dim sBuffer() As Byte
    Dim m_iBytesRead As Integer
    Dim iTotalBytes As Integer
    Dim myChar As Char
    Dim i As Integer
    iContentLength = myResponse.Cont entLength
    ' Dim responseStream As IO.Stream = myResponse.GetR esponseStream
    ' Dim responseReader As StreamReader = New
    StreamReader(re sponseStream)
    ' Dim writer2 As StreamWriter = New
    StreamWriter("c :\textStream2.t xt", Me.ckAppend.Che cked)
    ' writer2.Write(r esponseReader.R eadToEnd)
    ' writer2.Close()

    ReDim sTotalBuffer(iC ontentLength - 1)
    m_iBytesRead = 1
    iTotalBytes = 0
    Do Until m_iBytesRead = 0
    ReDim sBuffer(iConten tLength - 1)
    m_iBytesRead = br.Read(sBuffer , 0, iContentLength)
    ReDim Preserve sBuffer(m_iByte sRead - 1)
    If m_iBytesRead 0 Then Array.Copy(sBuf fer, 0, sTotalBuffer,
    iTotalBytes, sBuffer.Length)
    iTotalBytes += m_iBytesRead
    Loop
    Dim writer As StreamWriter = New StreamWriter("c :\textStream.tx t",
    Me.ckAppend.Che cked)
    writer.WriteLin e("Dumping HTML stream...")
    For i = LBound(sTotalBu ffer) To UBound(sTotalBu ffer)
    myChar = ChrW(sTotalBuff er(i))
    If sTotalBuffer(i) = 10 Then writer.Write(Ch r(13))
    writer.Write(my Char)
    Next
    writer.Close()
    End Sub


    Comment

    Working...