WebBrowser wait issue

madaxe

Member
Joined
Mar 18, 2008
Messages
16
Programming Experience
1-3
I want to pass a security key to my webserver use the web server to validate and build serverside a web page then in my form populate labels with the correct information.

in essence my code works asl ong as i first populate the webbrowser then select a button on my form to populate the information. BUt when i put the code below together in one sub it stops working im assuming its because the webbrowser does not have enough time to get the data.

I ahve tried loops waiting for the ready state but my program just hangs

Madaxe

VB.NET:
Dim Mywebbrowser As New WebBrowser
Mywebbrowser.Navigate("http://www.google.com/CGI_BIN/Key.cgi?Key=23456")

Dim els As HtmlElementCollection = Mywebbrowser.Document.All
Dim Element As HtmlElement = els.Item(0)
Dim String1 As String = Element.InnerText
Dim myarray = Strings.Split(String1, " ")
 
I'm a newby can you please show me how to use web service to get the contents of a html page.

I ahve tried using "HttpWebResponse" but it does not work when it has to go through a firewall for some reason.

So i was trying to figure out ulternatives like

copying the web page to the loacl machine extracting the data then delete it
cache the page on the local machine
can you please help

do you have any examples that i can learn from

Madaxe

I found a couple of scripts on the net and put them together see below
they work when i run it out side of my company. inside the "HttpWebResponse" line fails.


VB.NET:
Dim url As String = "http://www.google.com/"

        ' Creates an HttpWebRequest for the specified URL.
        Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)

        ' Sends the request and waits for a response.
        Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)

        ' Calls the method GetResponseStream to return the stream associated with the response.
        Dim receiveStream As Stream = myHttpWebResponse.GetResponseStream()
        Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
        ' Pipes the response stream to a higher level stream reader with the required encoding format.
        Dim readStream As New StreamReader(receiveStream, encode)

        Dim EOF As Boolean = False
        Label1.Text = ""

        Do While EOF = False

            Dim contents As String = readStream.ReadLine

            If InStr(contents, "textbar") <> 0 Then

                Label1.Text = Label1.Text & vbCrLf & contents

            End If


            If readStream.EndOfStream = True Then

                EOF = True

            End If

        Loop
        
        ' Releases the resources of the Stream.
        readStream.Close()
        ' Releases the resources of the response.
        myHttpWebResponse.Close()
 
Back
Top