Streamreader cutting data?

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

    #1

    Streamreader cutting data?

    Hi,

    I'm using a HttpWebRequest/HttpWebResponse to get plain html code off a
    website. This is the code:

    (...)
    Dim Resp As HttpWebResponse

    Try
    Resp = CType(request.G etResponse(), HttpWebResponse )
    Catch ex As Exception
    MsgBox(ex.ToStr ing)
    Return False
    End Try

    Dim resp1, resp2 As Integer
    resp1 = CInt(Resp.Conte ntLength)
    Dim sr As StreamReader = New StreamReader(Re sp.GetResponseS tream(),
    Encoding.Defaul t)
    Dim s As String = sr.ReadToEnd()
    resp2 = s.Length
    If resp1 <resp2 Then
    MsgBox("My HTTP response was cut!")
    End If

    The problem is that the last expression often and randomly evaluates to
    true (Resp.ContentLe ngth = 153850 and s.Length = 152450). Because of
    that the end of the HTML code is missing. When randomly s.Length
    evaluates to 153850, everything is ok and I have the full HTML code from
    the server.

    Does anyone have any idea on what could be causing this?

    --
    Kind Regards,
    Winger
  • Cor Ligthert [MVP]

    #2
    Re: Streamreader cutting data?

    Winger,

    Are you sure that it is missing because when there is a 00 value character
    in your string than the rest is not showed anymore.

    Cor

    "Winger" <winger@winger. spamu.nietoleru je.plschreef in bericht
    news:f3n97n$sga $1@inews.gazeta .pl...
    Hi,
    >
    I'm using a HttpWebRequest/HttpWebResponse to get plain html code off a
    website. This is the code:
    >
    (...)
    Dim Resp As HttpWebResponse
    >
    Try
    Resp = CType(request.G etResponse(), HttpWebResponse )
    Catch ex As Exception
    MsgBox(ex.ToStr ing)
    Return False
    End Try
    >
    Dim resp1, resp2 As Integer
    resp1 = CInt(Resp.Conte ntLength)
    Dim sr As StreamReader = New StreamReader(Re sp.GetResponseS tream(),
    Encoding.Defaul t)
    Dim s As String = sr.ReadToEnd()
    resp2 = s.Length
    If resp1 <resp2 Then
    MsgBox("My HTTP response was cut!")
    End If
    >
    The problem is that the last expression often and randomly evaluates to
    true (Resp.ContentLe ngth = 153850 and s.Length = 152450). Because of that
    the end of the HTML code is missing. When randomly s.Length evaluates to
    153850, everything is ok and I have the full HTML code from the server.
    >
    Does anyone have any idea on what could be causing this?
    >
    --
    Kind Regards,
    Winger

    Comment

    • Winger

      #3
      Re: Streamreader cutting data?

      Hi Cor,

      Cor Ligthert [MVP] wrote:
      Are you sure that it is missing because when there is a 00 value character
      in your string than the rest is not showed anymore.
      It is missing, what it is is I'm doing an application to automatically
      handle (fill & post) website forms, and the website is using VIEWSTATE
      and EVENTVALIDATION values hidden in the code which I need to get before
      I submit the form values.

      The HttpWebResponse I am trying to get (and part of which is missing at
      the end), when intermittently broken, is always broken in the middle of
      the EVENTVALIDATION value (which is several kilobytes).

      I take it that certain character in the EVENTVALIDATION string might be
      responsible for the problem, is that right? And if so, is there any way
      to process all the stream data?

      --
      Kind Regards,
      Winger

      Comment

      Working...