473,473 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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.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?

--
Kind Regards,
Winger
May 31 '07 #1
2 1361
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" <wi****@winger.spamu.nietoleruje.plschreef in bericht
news:f3**********@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.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?

--
Kind Regards,
Winger

Jun 1 '07 #2
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
Jun 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Liberal | last post by:
I am looking for the simplest forum, bbs script which has those features? new messages will be displayed only after the administrator reviewed allow users post without signing up display the...
9
by: oafyuf | last post by:
Hi, I'm having performanbce issues with StreamReader and was wondering what I could do to improve it... The following takes around 3 seconds to process! The content of the response is: ...
11
by: Tiger | last post by:
We can use seek() in the FileStream class,as we know. But I found that seek() is not work correctly in StreamReader. Who can tell me how to use seek() correctly in StreamReader? thanks a lot! I...
21
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the...
2
by: James Wong | last post by:
Dear all, I'm using StreamReader to read a text file containing BIG-5 data and found that no matter which encoding method in StreamReader's construction parameter, the BIG-5 contents become...
4
by: KenLee | last post by:
help!! I used StreamReader and StreamWrite. the problem is it doesn't write all readline. For example it read 100 line and write 51lines. this is codes. class kenlee{ private StreamWriter sw...
0
by: Al Wilkerson | last post by:
Hey, Has anyone ever got a "Unable to read data from transport connected" message after reading data from a streamreader composed of a networkstream. For example: Server TcpListener...
4
by: somequestion | last post by:
Question 1. i am using StreamReader Class like this... string str = string.Empty; StreamReader sr = new StreamReader(fsIn,Encoding.Default) while ((str = sr.ReadLine()) != null) { // wanna get...
3
by: stumorgan | last post by:
I'm doing some USB communications in C# and am running into a minor annoyance. I'm using the Windows API CreateFile function to get a SafeFileHandle, which I then stuff into a FileStream and from...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.