0

I am trying to build a IE plugin which have to make few webrequest on users behalf. To make a web request programatically I can using following code.

var url = "www.example.com";
var request = (HttpWebRequest)WebRequest.Create(url);
var response = (HttpWebResponse)request.GetResponse();

The response variable will have the response from the webserver. Now I want to execute this the response as it is will get executed in real browser (but hidden from the user;I can't use the real browser). There are few javascripts in this retrieved page, actually I want to execute them. Is it possible to do that somehow?

aMa
  • 629
  • 3
  • 10
  • 19

1 Answers1

0

It is possible. You have to instantiate a Windows.Forms.WebBrowser control without attaching it anywhere so it stays invisible. Then you have 2 options:

  • navigate to the URL with the Navigate method which means the whole page will be loaded as in a normal browser so you won't need to load the content with WebRequest in your code
  • load the HTML code to the WebBrowser control by setting the DocumentText property if you really would like to have HTML downloaded separately

The only concern is that this operation could be quite resource consuming so it would probably make sense to move it to a different process.

Miroshko
  • 863
  • 6
  • 14