Can I customize web browser control using HttpWebRequest?

Is there a way to make a WebBrowser control in C # .NET and requests made by HttpWebRequest to share cookies?

eg. if the request is executed programmatically with HttpWebRequest and then HttpWebResponse sets a cookie, is there any way to make sure that this is also set in the WebBrowser control?

and also, if the user navigates using the WebBrowser control and a cookie is set, is there a way to update CookieContainer for HttpWebRequest?

Thanks for any help!

+6
source share
2 answers

You will need to manually synchronize cookies using the InternetSetCookieEx / InternetGetCookieEx API, and this requires that you know all the URLs of all the subtasks used by this page.

You also need to pass the INTERNET_COOKIE_HTTPONLY flag to make sure the HTTPONLY cookie HTTPONLY displayed by your application.

+3
source
 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(myUri); request.CookieContainer = new CookieContainer(); request.CookieContainer.SetCookies(myUri, webBrowser1.Document.Cookie); 

( source )

And vice versa (I'm not sure):

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(myUri); //request.CookieContainer = new CookieContainer(); request.GetResponse(); webBrowser1.Document.Cookie = request.CookieContainer.GetCookies(myUri); 
+1
source

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


All Articles