Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow

    [Help] Problem reading text from a webpage

    Hey guys. I'm trying to use StreamReader to read all the text in a .txt document I uploaded on my ftp site...

    I'm currently using this to read 4 different text documents and print them into a label...

    [php]
    Dim url1, url2, url3, url4 As String
    url1 = "https://mywebsite/TextDocument1.txt"
    url2 = "https://mywebsite/TextDocument2.txt"
    url3 = "https://mywebsite/TextDocument3.txt"
    url4 = "https://mywebsite/TextDocument4.txt"

    Dim request1, request2, request3, request4 As System.Net.HttpWebRequest

    request1 = System.Net.HttpWebRequest.Create(url1)
    request2 = System.Net.HttpWebRequest.Create(url2)
    request3 = System.Net.HttpWebRequest.Create(url3)
    request4 = System.Net.HttpWebRequest.Create(url4)

    Dim response1, response2, response3, response4 As System.Net.HttpWebResponse
    response1 = request1.GetResponse()
    response2 = request2.GetResponse()
    response3 = request3.GetResponse()
    response4 = request4.GetResponse()

    Dim sr1, sr2, sr3, sr4 As System.IO.StreamReader

    sr1 = New System.IO.StreamReader(response1.GetResponseStream (), System.Text.Encoding.GetEncoding("windows-1252"))
    sr2 = New System.IO.StreamReader(response2.GetResponseStream (), System.Text.Encoding.GetEncoding("windows-1252"))
    sr3 = New System.IO.StreamReader(response3.GetResponseStream (), System.Text.Encoding.GetEncoding("windows-1252"))
    sr4 = New System.IO.StreamReader(response4.GetResponseStream (), System.Text.Encoding.GetEncoding("windows-1252"))

    Dim Online1, Online2, Online3, Online4 As String
    Online1 = sr1.ReadToEnd()
    Online2 = sr2.ReadToEnd()
    Online3 = sr3.ReadToEnd()
    Online4 = sr4.ReadToEnd()

    Label2.Text = ("1. " + Online1)
    Label3.Text = ("2. " + Online2)
    Label4.Text = ("3. " + Online3)
    Label5.Text = ("4. " + Online3)

    [/php]

    Only trouble is, nothing happens O.o

    Any glaring errors in my code?

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  2. #2
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    First, use this function:

    Code:
     
    Function GetPage(ByVal pageUrl As String) As String
    	  Dim s As String = ""
    	  Try
    		 Dim request As HttpWebRequest = WebRequest.Create(pageUrl)
    		 Dim response As HttpWebResponse = request.GetResponse()
    		 Using reader As StreamReader = New StreamReader(response.GetResponseStream())
    			s = reader.ReadToEnd()
    		 End Using
    	  Catch ex As Exception
    		 Debug.WriteLine("FAIL: " + ex.Message)
    	  End Try
    	  Return s
       End Function
    Then, Try this.

    Code:
    Dim url1, url2, url3, url4 As String
            url1 = "https://mywebsite/TextDocument1.txt"
            url2 = "https://mywebsite/TextDocument2.txt"
            url3 = "https://mywebsite/TextDocument3.txt"
            url4 = "https://mywebsite/TextDocument4.txt"
    Dim Online1, Online2, Online3, Online4 As String 
    Online1 = GetPage(url1)
    Online2 = GetPage(url2)
    Online3 = GetPage(url3)
    Online4 = GetPage(url4)

  3. The Following User Says Thank You to Hassan For This Useful Post:

    Jason (06-01-2010)

  4. #3
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by FLAMESABER View Post
    First, use this function:

    Code:
     
    Function GetPage(ByVal pageUrl As String) As String
    	  Dim s As String = ""
    	  Try
    		 Dim request As HttpWebRequest = WebRequest.Create(pageUrl)
    		 Dim response As HttpWebResponse = request.GetResponse()
    		 Using reader As StreamReader = New StreamReader(response.GetResponseStream())
    			s = reader.ReadToEnd()
    		 End Using
    	  Catch ex As Exception
    		 Debug.WriteLine("FAIL: " + ex.Message)
    	  End Try
    	  Return s
       End Function
    Then, Try this.

    Code:
    Dim url1, url2, url3, url4 As String
            url1 = "https://mywebsite/TextDocument1.txt"
            url2 = "https://mywebsite/TextDocument2.txt"
            url3 = "https://mywebsite/TextDocument3.txt"
            url4 = "https://mywebsite/TextDocument4.txt"
    Dim Online1, Online2, Online3, Online4 As String 
    Online1 = GetPage(url1)
    Online2 = GetPage(url2)
    Online3 = GetPage(url3)
    Online4 = GetPage(url4)
    Can I have your children?

    Thanks so much man, works beautifully and so much less messy Thanks.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  5. #4
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by J-Deezy View Post
    Can I have your children?

    Thanks so much man, works beautifully and so much less messy Thanks.
    No, I love my children...lol

    No problem...*cough* thnx !! ?
    xD

  6. The Following User Says Thank You to Hassan For This Useful Post:

    Jason (09-21-2010)

  7. #5
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by FLAMESABER View Post
    No, I love my children...lol

    No problem...*cough* thnx !! ?
    xD
    I meant can I make you some more silly

    I pressed thanks!

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  8. #6
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Quote Originally Posted by J-Deezy View Post
    I meant can I make you some more silly

    I pressed thanks!
    No, you can't...and thnx

  9. The Following User Says Thank You to Hassan For This Useful Post:

    Jason (09-21-2010)

  10. #7
    MvRouC12's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Location
    Stalking Choobs
    Posts
    1,690
    Reputation
    13
    Thanks
    246
    My Mood
    Amused
    Oh wow, and thanks. haha solved tag anyone?

    [IMG]https://i986.photobucke*****m/albums/ae345/TripleSixPf/Okami-MvRouC12.jpg[/IMG]
    Quote Originally Posted by m_t_h View Post


    By stop playing AVA untill brasilian server comes.

    Do you guys really need to ruin EVERY game?
    [IMG]https://i175.photobucke*****m/albums/w148/Guitarman1157/dontforget.gif[/IMG]

  11. #8
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Hey Flame if you happen to look at this thread again, is it possible to read one line, save it to a string variable, read the next line, save it to another string variable...etc

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  12. #9
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    Code:
    While Not reader.EndOfStream
    
                Dim s As String = reader.ReadLine
               
            End While
    You may do something like...

    Code:
    if s.startswith("abc")...
    Code:
    if s.contains("def")...
    I don't know how to declare a new variable for each line. You may use a hidden listbox or idk...tell me exactly why/how you want to do that ^.-



  13. #10
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Well basically what I want to do is have a few things associated to a general topic that I save in a text document.

    i.e my text document is set out like this

    [php]
    NAME
    LINK
    LINK2
    [/php]

    But I want to read the line that contains the line and assign it to a label
    then I want to read second line and assign that to another string variable

    I.e (this isn't actual code obviously but I hope it helps you understand better what i mean)

    [php]

    Dim DocName, DocLink1, DocLink2 as string
    Dim request As HttpWebRequest = WebRequest.Create(pageUrl)
    Dim response As HttpWebResponse = request.GetResponse()
    Using reader As StreamReader = New StreamReader(response.GetResponseStream())

    DocName = reader.ReadLine1
    DocLink1 = reader.ReadLine2
    DocLink2 = reader.ReadLine3

    end using

    [/php]

    But you can't tell it what line to read :O

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  14. #11
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    One second....



  15. #12
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Blubb1337 View Post
    One second....

    ........one

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  16. #13
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    Fu.

    Add the following function:

    Code:
      Public Shared Function ReadSpecifiedLine(ByVal file As String, ByVal lineNum As Integer) As String
            'create a variable to hold the contents of the file
            Dim contents As String = String.Empty
            'always use a try...catch to deal
            'with any exceptions that may occur
            Try
                Using stream As New StreamReader(file)
                    contents = stream.ReadToEnd().Replace(vbCr & vbLf, vbLf).Replace(vbLf & vbCr, vbLf)
                    Dim linesArray As String() = contents.Split(New Char() {ControlChars.Lf})
    
                    'Make sure we have ana ctual array
                    If linesArray.Length > 1 Then
                        'Make sure user didnt provide number greater than the number
                        'of lines in the array, and not less than 0 (zero) Thanks AdamSpeight2008
                        If Not lineNum > linesArray.Length AndAlso Not lineNum < 0 Then
                            Return linesArray(lineNum)
                        Else
                            'Failed our check so return the first line in the array
                            Return linesArray(0)
                        End If
                    Else
                        'No array so return the line
                        Return contents
                    End If
                End Using
            Catch ex As Exception
                Return ex.ToString()
            End Try
        End Function
    Code:
    Dim s as string = reader.readtoend
    Code:
    DocName = ReadSpecifiedLine(s, 0)         
                DocLink1 = ReadSpecifiedLine(s, 1)
                DocLink2 = ReadSpecifiedLine(s, 2)
    Eating, fu again.
    Last edited by Blubb1337; 06-02-2010 at 05:46 AM.



  17. #14
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Blubb1337 View Post
    Fu.

    Add the following function:

    Code:
      Public Shared Function ReadSpecifiedLine(ByVal file As String, ByVal lineNum As Integer) As String
            'create a variable to hold the contents of the file
            Dim contents As String = String.Empty
            'always use a try...catch to deal
            'with any exceptions that may occur
            Try
                Using stream As New StreamReader(file)
                    contents = stream.ReadToEnd().Replace(vbCr & vbLf, vbLf).Replace(vbLf & vbCr, vbLf)
                    Dim linesArray As String() = contents.Split(New Char() {ControlChars.Lf})
    
                    'Make sure we have ana ctual array
                    If linesArray.Length > 1 Then
                        'Make sure user didnt provide number greater than the number
                        'of lines in the array, and not less than 0 (zero) Thanks AdamSpeight2008
                        If Not lineNum > linesArray.Length AndAlso Not lineNum < 0 Then
                            Return linesArray(lineNum)
                        Else
                            'Failed our check so return the first line in the array
                            Return linesArray(0)
                        End If
                    Else
                        'No array so return the line
                        Return contents
                    End If
                End Using
            Catch ex As Exception
                Return ex.ToString()
            End Try
        End Function
    Code:
    Dim s as string = reader.readtoend
    Code:
    DocName = ReadSpecifiedLine(s, 0)         
                DocLink1 = ReadSpecifiedLine(s, 1)
                DocLink2 = ReadSpecifiedLine(s, 2)
    Eating, fu again.
    hehehe thanks Blubb, I'll go checkit out now! My back is like crippled so im bored as fuck

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  18. #15
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    Code something for me, no I don't know what x_X.

    U no onlaine @ msn?



Page 1 of 2 12 LastLast

Similar Threads

  1. [Help]How to draw text from a file?
    By seeplusplus in forum Combat Arms Coding Help & Discussion
    Replies: 29
    Last Post: 10-05-2010, 04:47 PM
  2. [help]read text from an online .txt[Solved]
    By trevor206 in forum Visual Basic Programming
    Replies: 10
    Last Post: 09-24-2010, 03:36 PM
  3. [Help]VB Read text file[Solved]
    By mo3ad001 in forum Visual Basic Programming
    Replies: 3
    Last Post: 06-16-2010, 03:49 AM
  4. Reading lines from text file?
    By ppl2pass in forum Visual Basic Programming
    Replies: 4
    Last Post: 02-23-2010, 09:27 AM
  5. Any1 from EU i need your help::: MUST READ EU USERS:::
    By headsup in forum Combat Arms Europe Hacks
    Replies: 1
    Last Post: 05-06-2009, 11:43 AM