Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 3rd, 2004, 04:46 PM
Registered User
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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(""), 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()

            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
    End Function
************************************************** ********************

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can not open http://.... aspx file cJeffreywang ASP.NET 2.0 Professional 3 July 2nd, 2007 10:13 PM
Read Text file and convert to Binary file VB.net sjlsysprg1 Pro VB.NET 2002/2003 4 June 29th, 2007 06:53 AM
How to read HTTP Body using servelts rammohan Servlets 2 July 1st, 2006 08:02 PM
Download a file from http location sarath_lal007 ASP.NET 1.0 and 1.1 Professional 1 February 17th, 2006 05:34 AM
Download file through HTTP KCUK Beginning VB 6 0 August 19th, 2005 07:20 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.