C # Use WebBrowser to obtain complete cookies

Source: Internet
Author: User

 

In fact, it is quite easy to operate a web page in WebBrowser, which can easily implement custom Website access habits. WebBrowser, after all, is the encapsulation of the native control of MS. When we use the WebBrowser under C #, especially in this way, although it is more convenient for you to remove it, but his convenience is at the cost of flexibility.

One day I want to use WebBrowser to obtain the COOKIE of a website. When I call Document. Cookie, I find that the COOKIE cannot be fully obtained and cannot be completely understood. This simple function will make WebBrowser look funny. After packet capture analysis, it is found that the website adds httponly to the key cookies written to the user end.

HttpOnly is actually a function to improve the security of WEB site applications, but it is often ignored. For example, this sub-configuration is provided in the preparation file of ASP. NET 2.0 web. config.

Reprinted please indicate the source: http://www.mobans.cn/net/1524.html

1 2 // the. NET code is as follows:
3 HttpCookie myCookie = new HttpCookie ("myCookie ");
4 myCookie. HttpOnly = true;
5 Response. AppendCookie (myCookie );

 

This is just a small setting. WebBrowser has nothing to do with him, but has checked a lot of information. To achieve this function, you must read and write the original network stream, this method is too difficult for many programmers to implement. The following is a simple implementation method.

 

1 public string Cookie ()
2 {
3 if (this. Url = null)
4 return null;
5 strin

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.