Read File Using HTTP
Hello People,
I´m using the code below to read a file in a URL address. But the problem is that I have this line in the file wich contain "Contagem P g. 3082". So I read the file line by line searching for a line that starts with "Contagem P g." then gotcha! I got the number that comes after that. I´m using this code:
************************************************** ********************
Dim webreq As Net.HttpWebRequest = CType(Net.WebRequest.Create("http://10.1.200.41/printer/"), Net.HttpWebRequest)
Dim webresp As Net.HttpWebResponse = CType(webreq.GetResponse(), Net.HttpWebResponse)
Dim strm As New System.IO.StreamReader(webresp.GetResponseStream() )
************************************************** ******************
The problem is that the StreamReader return to me the string "Contagem Pg." without the space between "P" and "g"
So when i search for "Contagem P g." the code don´t find it because the StreamReader returns "Contagem Pg."
Anyone can Help me??
Complete Function Code Below:
************************************************** ******************
Function PegaContador(ByVal httpaddress As String, ByVal stringtosearch As String) As String
Dim webreq As Net.HttpWebRequest = CType(Net.WebRequest.Create(httpaddress), Net.HttpWebRequest)
Dim webresp As Net.HttpWebResponse = CType(webreq.GetResponse(), Net.HttpWebResponse)
Dim strm As New System.IO.StreamReader(webresp.GetResponseStream() )
Label1.Text = webresp.ContentEncoding
Dim line As String
Dim strCount As String
Dim strSize As Integer = stringtosearch.Length()
Do
line = strm.ReadLine
If line <> "" Then
If line.StartsWith(stringtosearch) Then
strCount = line.Substring(strSize)
strCount = Trim(strCount)
Return strCount
End If
End If
Loop Until line Is Nothing
strm.Close()
End Function
************************************************** ********************
|