Streamreader cutting data?

W

Winger

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.GetResponse(), HttpWebResponse)
Catch ex As Exception
MsgBox(ex.ToString)
Return False
End Try

Dim resp1, resp2 As Integer
resp1 = CInt(Resp.ContentLength)
Dim sr As StreamReader = New StreamReader(Resp.GetResponseStream(),
Encoding.Default)
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.ContentLength = 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?
 
C

Cor Ligthert [MVP]

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
 
W

Winger

Hi Cor,
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top