HTTPWeb Request/Response

tjgrindsted
tjgrindsted used Ask the Experts™
on
Hi i have this code, that shows a soccer match ranklist.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Dim request As HttpWebRequest = CType(WebRequest.Create("http://www.dbu.dk/turneringer_og_resultater/resultatsoegning/position.aspx?poolid=135814"), HttpWebRequest)
        Dim response As HttpWebResponse = CType(Request.GetResponse(), HttpWebResponse)
        Dim reader As StreamReader =  New StreamReader(response.GetResponseStream(),Encoding.GetEncoding("iso-8859-1"))
  

        Dim input As String = reader.ReadToEnd()
        Dim StartToken As String = "<div id="div2"></div>"
        Dim EndToken As String = "<div class="PageUnionInfo" id="PageUnionInfo" style="margin-bottom:4px;">"
        Dim ContentStartPosition As Integer = input.IndexOf(StartToken) + StartToken.Length
        Dim ContentEndPosition As Integer = input.IndexOf(EndToken)
        Dim Length As Integer = ContentEndPosition - ContentStartPosition
        Dim Content As String = intput.Substring(ContentStartPosition, Length)
        someLabel.Text = Content
    End Sub

Open in new window


this code will the ranking list.
My question is, if i need to find a targ/name maybe like "c01 first" and i need to go 8 steps after the name and then show the text from that place to the next "<" how do i do that in asp.net.

In asphttp i know that i can do it like this:

Read=instr(ReadEnd,strResult,"c01 first")+8
ReadEnd=instr(Read,strResult,"<")
Team1=mid(strResult,Read,ReadEnd-Read)

but how do i do it in ASP.NET !?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Luis PérezSoftware Architect in .Net

Commented:
This is a port "as is" of your code to Vb.net. I think it will work without problems.

Dim Read As Integer = strResult.IndexOf("co1 first", ReadEnd) + 8
Dim ReadEnd As Integer = strResult.IndexOf("<", Read)
Dim Team1 As String = strResult.Substring(Read,ReadEnd-Read)

Hope that helps.

Author

Commented:
Hi i have looked at it 3 days now, but im stuck...

If i use this code
Imports System.Net
Imports System.IO
Imports System.Text

Partial Class eks2
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Dim objRequest As HttpWebRequest = WebRequest.Create("http://www.dbu.dk/turneringer_og_resultater/resultatsoegning/position.aspx?poolid=135814")
        Dim objResponse As HttpWebResponse = objRequest.GetResponse()
        Dim Output As String = ""
        Using reader = New StreamReader(objResponse.GetResponseStream(), Encoding.GetEncoding("iso-8859-1"))
            Output = reader.ReadToEnd()
        End Using

        Output = Output.Substring(Output.IndexOf("<div id=""div2""") + 21)
        Output = Output.Substring(0, Output.IndexOf("<div class=""PageUnionInfo"" id=""PageUnionInfo"" style=""margin-bottom:4px;"">"))

        Dim ReadEnd As Integer = ""
        Dim Read As Integer = ""
        Dim strResult As String Output.ReadToEnd()
        Read = strResult.IndexOf("poolid=", ReadEnd) + 15
        ReadEnd = strResult.IndexOf("<", Read)
        Dim Team1 As String = strResult.Substring(Read, ReadEnd - Read)

        someLabel.Text = Team1
        'It will writeout Varde IF  (1)

    End Sub

End Class

Open in new window


If u delete this part and the set someLable.Text = Output the i get the result table...
But when i add this part then i cant get the name Varde IF (1) from the output result
        Dim ReadEnd As Integer = ""
        Dim Read As Integer = ""
        Dim strResult As String Output.ReadToEnd()
        Read = strResult.IndexOf("poolid=", ReadEnd) + 15
        ReadEnd = strResult.IndexOf("<", Read)
        Dim Team1 As String = strResult.Substring(Read, ReadEnd - Read)

        someLabel.Text = Team1
        'It will writeout Varde IF  (1)

Open in new window


Hope u can help me !!

Author

Commented:
Someone that can help me here !?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Author

Commented:
bump
closed

Author

Commented:
post closed

Author

Commented:
post closed

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial