0

I am using a VB.NET program that uses the WebBrowser control to navigate the Web. The site that I need to navigate to suddenly became not IE-friendly. So, I am thinking to try to make it look to the site that the WebBrowser control is not IE, but a Mozilla Firefox browser. How can I do that? Can I change an HTTPrequest header that the control sends? Or something like that? Thank you!

------------- Edit --------------

Hi, xxbbcc! Thanks for your big answer. HttpWebRequest is about the only option that I have left. I used to work with that in the past, but I doubt it will work in the case of a site that I need.

The problem is - the site uses a LOT of scripting to build the web page, and the button that has to be clicked is actually a link that evokes a script and then the page is built even further. That final HTML code is what I need.

Now the problem is even more complicated than I thought. It absolutely does not matter what user-agent is specified in the request headers (I found it out with the Fiddler, thanks to jfmags). What seems to matter is that after the site redirects the browser to an HTTPS address, Firefox keeps sending HTTP/1.1 requests, while IE starts sending HTTP/1.0 requests, and that is how it probably fails. This is made by design by site owners. I found a discussion on the Net about this here http://answers.microsoft.com/en-us/ie/forum/ie8-windows_other/how-to-force-ie-to-use-http11-over-ssl-through/360eca2d-e290-4078-ad37-7665bec706c4 , but it does not seem conclusive. I used to work with the Mozilla ActiveX Control but it is obsolete now, since the project was discontinued.

The site that I am talking about is this notorious site.

I know, I am a pirate, it is bad. By downloading a film I probably cause a multimillion dollar loss to some huge and incredibly rich companies. But where I live, it is just impossible to buy a film with original sound, they are all crippled by dubbing. So, what options do I have left? I like films.

I will try to see if the HttpWebRequest can pull this off.

GreenBear
  • 373
  • 1
  • 6
  • 18
  • Possible duplicate of this: http://stackoverflow.com/questions/937573/changing-the-useragent-of-the-webbrowser-control-winforms-c-sharp – jmaglio Feb 28 '12 at 01:06
  • Thanks, jfmags! I am getting there too. I am not very good at C#, though. How would it look in VB.NET? – GreenBear Feb 28 '12 at 01:11
  • Ok. I tried this: WebBrowser1.Navigate(TextBox1.Text, "", Nothing, "User-Agent: Mozilla/5.0 (Windows NT 6.2; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"). Does not work, probably because the site redirects :( – GreenBear Feb 28 '12 at 01:31
  • 1
    Are you sure it's an IE thing? You can change the user-agent sent using Fiddler to make sure it solves the problem. Maybe there is something else going on. – jmaglio Feb 28 '12 at 01:44
  • The site opens in Firefox, does not open in IE8, IE9, the WebBrowser control. I am not sure how they do it, but I am sure they do it on purpose. What is Fiddler? – GreenBear Feb 28 '12 at 01:50
  • Do you mean this http://fiddler2.com/fiddler2/ ? – GreenBear Feb 28 '12 at 01:53
  • 1
    Yeah - that's it. If you install it, you can change the user-agent under the Rules menu and see if the responses change. – jmaglio Feb 28 '12 at 01:57
  • But the question still holds. How can I change the headers of all requests? I do not think beforeNavigate fires at every request. – GreenBear Feb 28 '12 at 02:00
  • Thank you, jfmags. Fiddler did it. It changes UserAgent for every request. Unfortunately, that does not solve the problem with the site. Somehow the site finds out that this is IE :( It was worth a try, though. – GreenBear Feb 28 '12 at 02:45

3 Answers3

1

You can read up on GeckoFX. It's a control similar to WebBrowser but it runs on the Gecko engine (same engine Firefox runs on).

http://code.google.com/p/geckofx/

brian
  • 15
  • 1
  • 6
0

You can't. The Web Browser control is Internet Explorer.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
0

You can change the request header to masquarade the browser control as Firefox but the response you'll get will be for Firefox, not for IE, so the WebBrowser control probably won't render it correctly.

Indeed, the WebBrowser control is IE.

Edit:

In your comment you said, you only need the HTML of a page to simulate a button click on that page. If this is the case, you can try using the HttpWebRequest/HttpWebResponse objects to send/receive HTTP requests to a server. You can use these to send any header so you can easily simulate any browser by sending the right headers. You can use Fiddler to first navigate to the site and save the requests in Firefox and then use information from those requests to build your HttpWebRequest objects.

Once you have the HTML in hand, you can parse it and do however you please. If you need to click a button that triggers a postback to the server, you can likely parse relevant data from the HTML response and then build a POST request. HttpWebRequest works in both synchronous and asynchronous modes, so you can either download a page using a few lines of code or you can control the entire download process (this is more complicated).

I know this is not what you initially asked about but if you don't actually need to display the page content, this may work better for you.

xxbbcc
  • 16,930
  • 5
  • 50
  • 83
  • I actually need a Web page HTML code, it does not matter how it looks. And I need to click a button on the Web page. – GreenBear Feb 28 '12 at 01:33
  • As I see it, while loading a page the WebBrowser sends multiple requests. How can I change headers of all of these requests before they are dispatched? – GreenBear Feb 28 '12 at 01:40
  • @GreenBear I updated my answer with details. If you only need to download a page to get the HTML (not to display it), you may be better off not using the WebBrowser control at all. `HttpWebRequest` may work better for you in that case. Let me know if I misunderstood what you need. – xxbbcc Feb 28 '12 at 08:28
  • Hi, xxbbcc! Thanks! I edited my question above. It was not quite clear anyway. – GreenBear Feb 28 '12 at 22:10