PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

GPRS: invalid segment length

Hello!

I'm using the following code for getting a GPRS internet connection and requesting a HTTP script on a pocket pc using VB .NET:


Dim url As New
Uri("http://www.url.de/file.php?variable1=1&variable2;=2")
Dim Req As WebRequest
Req = WebRequest.Create(url)
Dim Resp As WebResponse
Try
Resp = Req.GetResponse
Catch exc As Exception
MsgBox(exc.Message)
Exit Sub
End Try
Dim netStream As StreamReader
netStream = New StreamReader(Resp.GetResponseStream)
txtURL.Text = netStream.ReadToEnd

There is only one problem again:
The execution of the command "netStream.ReadToEnd" in the last line results
in the following error:
"Exception of type 'System.IO.IOException' in System.dll.
Additional information: invalid segment length."

The page I want to download exists, but it's not a complete HTML page, but
only a result of a script with about 30 characters. Might that be a problem
or why do you thing this error occurs?

Thanks again
Ok, to me it looks like it should work like it is. So, try skinning the cat in a different way:

Sample code straight out of MSDN:

Code:
' Create a 'WebRequest' object with the specified url
Dim myWebRequest As WebRequest = WebRequest.Create("www.contoso.com")

' Send the 'WebRequest' and wait for response.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

' Call method 'GetResponseStream' to obtain stream associated with the response object
Dim ReceiveStream As Stream = myWebResponse.GetResponseStream()

Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")

' Pipe the stream to a higher level stream reader with the required encoding format.
Dim readStream As New StreamReader(ReceiveStream, encode)
Console.WriteLine(ControlChars.Cr + "Response stream received")
Dim read(256) As [Char]

' Read 256 charcters at a time .
Dim count As Integer = readStream.Read(read, 0, 256)
Console.WriteLine("HTML..." + ControlChars.Lf + ControlChars.Cr)
While count > 0

' Dump the 256 characters on a string and display the string onto the console.
Dim str As New [String](read, 0, count)
Console.Write(str)
count = readStream.Read(read, 0, 256)

End While
Console.WriteLine("")

' Release the resources of stream object.
readStream.Close()

' Release the resources of response object.
myWebResponse.Close()


I suggest you use a StringBuilder to accumulate a string, rather than dumping to the console, but the above should give you the idea.

If it still fails then look at using an asynchronous receive rather than the synchronous one, maybe...