user1017524
user1017524

Reputation: 241

C#: How to make HttpWebRequest mimic the Web Browser control

I've used several HttpWebRequest's in the past but they've all been used to login into a site.

I was wondering how does one make the WebRequest mimic a WebBrowser as in once you're logged in, navigate to a new page, maybe perform an action there, then go to a different page?

I've researched a little about this before and I think it might involve using the prior request's cookies or something.

My question is how do I (I'm assuming) get the cookies from the previous session, then navigate to a page, or complete an action as if we were still on the last request if that makes sense.

Upvotes: 4

Views: 2001

Answers (1)

Sam Axe
Sam Axe

Reputation: 33738

the HttpWebRequest has a Cookies property and HttpWebResponse has a CookieContainer property.

you record the cookies from the container, and add them to the next request.

you may also need to set the HTTP referrer header field on the request object.

EDIT :
this will still not get you mimicking a web browser. things like JavaScript will not work/run. and you won't have a DOM to work against.

Upvotes: 1

Related Questions