Problem in using AxWebBrowser component in C# application

Posted on 2006-04-13
Last Modified: 2012-06-21
I have a C# windows application form which embeds a AxWebBrowser component in it.
I specified the html file URL(a.html) in the navigate method of the component.

In the body onload method of the a.html I have a automatic redirect to some other html file(b.html).

Now I want to capture the text or the html of the redirected html file(b.html) . I cannot specify this file name(b.html) in the navigate method as I have to pass some parameters from the first file so I can specify only the first file name(a.html) in the navigate method of the AxWebBrowser component.

I did try with the following code. I try to use the navigate event of the AxWebBrowser component

  private void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
                  doc = (mshtml.IHTMLDocument2)axWebBrowser1.Document;


The above method is retrieving only the contents of the a.html. Is there a way to retrieve the contents of the b.html without actually specifying the url of b.html file in the navigate method.

Or is there a way in C# to use the HTTPWebResponse related objects to accomplish the above scenario(Get the contents of the second html file automatically).

Somebody please help in this.
Question by:felixmosesj
    LVL 12

    Expert Comment

    I don't know about the AxWebBrowser autoredirecting, but you can definitely do this with the HttpWebRequest etc objects. When you say "there is an automatic redirect" is that a 302 response from the browser, or is it a meta http-equiv="REFRESH" tag in the page head? If it is a 302 then the HttpWebRequest method is very simple. Either way I can post a quick example if you want it.


    Author Comment

    It is not refresh tag and I am not sure about the 302 redirect. The code in the a.html file is this

    function postForm()

    <body onload="postForm();" MS_POSITIONING="GridLayout">
                <form id="Form1" name="Form1" method="post" action="https://localhost/b.html" language="javascript" id="Form1">
    Some important Statements Here

    Now I want to get the response of the b.html file. Directly I should not get the response of the b.html. First my a.html file should load and then it gets automatically redirected to b.html and finally I should get the text or html content of b.html file. If possible please post a sample code.
    LVL 12

    Accepted Solution

    Ok, well you aren't going to have quite such an easy ride, but you can do it with HttpWebRequest. I'll be able to get code to you, but not until Tuesday next week - I'm on holiday to then. Until I do, the basic premise will be to use the HttpWebRequest to request a.html. You will get the response from a.html and include that in a POST request which you will put into a second HttpWebRequest, this will return b.html.

    To do this, I would first install Fiddler (if anyone is counting how many times I mention Fiddler, no I have no conflict-of-interest here ;) I just think it invaluable), and then open a.html and watch it redirect to b.html in a browser. That will allow you to recreated the form POST that is generated from a.html submitting it's form onload. You can then use this with the HttpWebRequest objects.

    I just started to hack out the code, and realised it will take me more than 5 minutes. Google gave me these Urls for doing it, they are a bit rough, but they are exactly right:

    To get "a.html"
    Then you need to read the values out that you want to post back , put them in a post string, and use:
    to do the post.

    We can work though something solid when I'm back next week, but let me know if that helps or not

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now