C #: How to get HttpWebRequest to mimic a web browser control

In the past, I used several HttpWebRequest , but all of them were used to enter the site.

I was wondering how to make WebRequest mimic a WebBrowser so that when you are logged in, go to a new page, maybe follow an action there, and then go to another page?

I already knew a little about this, and I think it could be due to the use of cookies from previous requests or something else.

My question is: how do I (I assume) get cookies from a previous session, then go to the page or perform the action as if we were on the last request, if that makes sense.

+4
source share
1 answer

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

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

You may also need to set the HTTP referrer header field for the request object.

EDIT:
it still won’t help you simulate a web browser. things like javascript will not work / work. and you will not have a DOM to work with.

+1
source

Source: https://habr.com/ru/post/1384416/


All Articles