Reputation: 373
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.
Upvotes: 0
Views: 2458
Reputation: 15
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/
Upvotes: 1
Reputation: 17327
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.
Upvotes: 0