views:

237

answers:

1

Hi,

I want to simulate the behaviour of the WebTestRequest class (in Visual Studio's Test Tools framework) where it can invoke dependent requests based on resources that are referred to in the response that is obtained from the original request.

For example, if I issue a web request and get the response by doing this:

string url = "http://www.mysite.com";
WebRequest request = WebRequest.Create(url);
using (WebResponse response = request.GetResponse())
{
    StreamReader reader = new StreamReader(response.GetResponseStream()); 
    string responseText = reader.ReadToEnd();
}

I would like to be able to parse responseText and see if there are any requests to other resources (like js/css files, images, etc.)

Is there an easy way of doing this? I hesitate to manually do this, as some of the resource requests may be set up programmatically and may not be obvious on a straightforward text parse.

A: 

Use a html/sgml parser library. I'm not familiar with Visual Studio, but there are frameworks for parsing html out there. Find one and look in the API for something related to finding elements.

xyld
Just to be clear, I'm already using the IHTMLDocument3 interface to build up a document object for html element extraction. I'm more interested in figuring out what dependent requests I should execute, based on the response. Do you know of an html parser that would enable me to do this?
Shoko
Sounds like you want a full-fledged web engine. Webkit is such a thing. If you REALLY need that, which I'm not sure you do, then you could look into that. Sorry I can't be of any more help.
xyld