locked
How to use Webbrowser to display a page obtained it with Webrequest/webresponse and continue the navigation in that webbrowser window RRS feed

  • Question

  • I got a page using Webrequest/Webresponse with the following code , returning  a struc with html member wher the function copy the HTML of the page:

     

    Public Function HttpGet(ByVal url As String, Optional ByVal request As String = "") As Response
      Dim webReq As HttpWebRequest
      Dim webResp As HttpWebResponse
      If request <> "" Then url = url & "?" & request
      Dim ourUri As Uri = New Uri(url)
      HttpGet = New Response
      HttpGet.Success = False
      LastException = Nothing
    
      ' necesitamos el cookie 
      webReq = CType(WebRequest.Create(ourUri), HttpWebRequest)
      webReq.CookieContainer = _cookieJar
      webReq.Credentials = CredentialCache.DefaultCredentials
      webReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0; .NET CLR 2.0.50727)"
      webReq.Timeout = timeout
      webReq.Method = "GET"
    
      ' hacemos el request
      Try
       webResp = webReq.GetResponse
      Catch ex As WebException
       Try
        Debug.Print(Format(Now(), "hh:mm:ss") & " Count = " & ExceptionCount & ex.Message)
    
        ExceptionCount = ExceptionCount + 1
    
        If ExceptionCount > 2 Then 'Or ex.Message = "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server." Then
         LastException = ex
         HttpGet.Success = False
         Exit Function
        End If
        HttpGet = HttpGet(url, request)
        Exit Function
       Catch ex1 As Exception
        LastException = ex1
        HttpGet.Success = False
        Exit Function
       End Try
       ' procesar el error
       LastException = ex
       HttpGet.Success = False
       Exit Function
      End Try
    
    
      HttpGet.StatusCode = webResp.StatusCode
      If webResp.StatusCode = HttpStatusCode.OK Then
       ' devolvemos el string
       Dim readStream As New StreamReader(webResp.GetResponseStream, System.Text.Encoding.ASCII)
       HttpGet.Html = readStream.ReadToEnd()
       HttpGet.Success = True
       readStream.Close()
      End If
      webResp.Close()
     End Function
    

     

    Now I want to display in a WebBrowser control and from here I want to navigate using the WebBrowser control.

    I Use the follwing code to do that :

     

    Private Sub LoginButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginButton.Click
      Dim Resp As Response
    
      Resp = Login()
    
      If Resp.Success Then
       
       Dim Doc As HtmlDocument
       Browser.ScriptErrorsSuppressed = True
    
       Try
        Doc = Browser.Document
        Browser.DocumentText = "<HTML><BODY></BODY></HTML>"
        Doc = Browser.Document.OpenNew(True)
    
    
        Doc.Write(Resp.Html)
    
       Catch ex As Exception
        MsgBox("Error :" & ex.Message)
       End Try
    
      End If
    
     End Sub
    

     

     

    The problem is when I click in any button of this page i Get in the screen only the Java command like : "forward?application=ui" but nothing else

    Could somebody tell me how is the correct way to handle  that?

    Thanks,

    Carlos

    Wednesday, October 20, 2010 9:30 PM

Answers