Torna al Thread

[CODE] Dim testohtml As String Dim righe As Integer = 0 Dim textS As String Private Sub RichiestaWEB() 'Crea una richiesta per un link Dim httprequest As WebRequest = HttpWebRequest.Create("http://javapc.poste.it/trackingPacchi") 'Se richiesta dal server setta i credenziali d'accesso e post dei dati httprequest.Credentials = CredentialCache.DefaultCredentials httprequest.Method = "POST" httprequest.ContentType = "application/x-www-form-urlencoded" Dim encoding As New System.Text.ASCIIEncoding Dim postData As String = "Action=ActionTracking&Method=Tracking&SessionID=-1&ldv=" & Me.TextBox1.Text ' 'INIZIO PARTE DA CAPIRE... ' Dim arByte As Byte() = encoding.GetBytes(postData) httprequest.ContentLength = arByte.Length Dim newStream As IO.Stream = httprequest.GetRequestStream newStream.Write(arByte, 0, arByte.Length) newStream.Close() ' 'FINE PARTE DA CAPIRE ' 'Prendi la risposta Dim risposta As HttpWebResponse = CType(httprequest.GetResponse(), HttpWebResponse) 'Prendi lo stream contenente gli oggetti mandati dal server Dim datastream As Stream = risposta.GetResponseStream 'Apri un stream usando uno StreamReader for facilità d'accesso Dim lettura As New StreamReader(datastream) 'Leggi il contenuto Dim letturahtml As String = lettura.ReadToEnd 'Chiudi gli stream lettura, datastream, risposta lettura.Close() datastream.Close() risposta.Close() testohtml = letturahtml Dim numerolinea1 As Integer Dim numerolinea2 As Integer Dim numerofine As Integer Dim iniziotable As String = "<table border=""0"" cellspacing=""2"" cellpadding=""3"" width=""100%"">" Dim finetable As String = "<BR>" numerolinea1 = InStr(testohtml, iniziotable) testohtml = testohtml.Remove(1, numerolinea1 - 1) numerolinea2 = InStr(testohtml, finetable) numerofine = testohtml.Length.ToString - numerolinea2 testohtml = testohtml.Remove(numerolinea2 - 1, numerofine) Dim rtab As String = "<tr bgcolor=""#e8f404"">" Dim posizione As Integer = 0 Numero_righe_tabelle: posizione = testohtml.IndexOf(rtab, posizione) If posizione <> -1 Then righe += 1 posizione += rtab.Length GoTo Numero_righe_tabelle End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click RichiestaWEB() textS = Nothing textS = testohtml Dim charconsiderato As Integer Dim parteriga1 As String = "<tr bgcolor=""#e8f404""><td><font size=1><b>" Dim parteriga2 As String = "</b></font></td><td><font size=1><b>" Dim parteriga3 As String = "</b></font></td></tr>" Dim parteriga4 As String = " .FINE RIGA " & righe charconsiderato = InStr(textS, parteriga1) textS = textS.Remove(0, charconsiderato - 1) Dim i As Integer = 0 For i = 0 To righe - 1 charconsiderato = InStr(textS, parteriga1) textS = textS.Insert(charconsiderato - 1 + 42, "INIZIO RIGA" & i + 1 & " $1$") textS = textS.Remove(charconsiderato - 1, 42) charconsiderato = InStr(textS, parteriga2) textS = textS.Insert(charconsiderato - 1, "$2$") textS = textS.Remove(charconsiderato + 2, 36) charconsiderato = InStr(textS, parteriga2) textS = textS.Insert(charconsiderato - 1, "$3$") textS = textS.Remove(charconsiderato + 2, 36) charconsiderato = InStr(textS, parteriga3) textS = textS.Remove(charconsiderato - 1, 21) textS = textS.Insert(charconsiderato - 1, " .FINE RIGA " & i + 1) Next charconsiderato = InStr(textS, parteriga4) Dim uno As Integer = charconsiderato + parteriga4.Length Dim due As Integer = textS.Length - uno textS = textS.Remove(uno - 1, due - 1) RichTextBox1.Text = textS[/CODE]
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5