Link to home
Start Free TrialLog in
Avatar of tjgrindsted
tjgrindsted

asked on

HTTPWeb Request/Response

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 !?
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

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.
Avatar of tjgrindsted
tjgrindsted

ASKER

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 !!
Someone that can help me here !?
bump
ASKER CERTIFIED SOLUTION
Avatar of tjgrindsted
tjgrindsted

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
post closed
post closed