After a long time, I finally figured out the relationship between the two. I can't live up to my time in the morning ~~~
For more information about the nature of HttpWebRequest. CookieContainer and HttpWebResponse. Cookies, MSDN and many other blogs, I will not talk about them anymore. If you do not know about them, go and have a look.
Now let's talk about the differences between them. All the shoes that have used these two attributes have found that in most cases, the content of the two is the same. They should all store cookies related to this link, but they are a little different:
The Cookie contained in HttpWebRequest. CookieContainer is all Cookies related to this request. However, HttpWebResponse. Cookies only contain Cookies related to the URL of the last request in this request.
What about Shenma? The key isRedirectionThat is to say, if defa1.1.aspx is currently accessed and Default1.aspx generates a Cookie named "Default1" and redirects it to the Default2.aspx page. On the Default2.aspx page, a Cookie named "Default2" is generated and redirected to the Default3.aspx page. A "Default3" Cookie is generated on the defa3.3.aspx page. So far, the entire request has ended.
HttpWebRequest. CookieContainer contains three cookies: "Default1, Default2, and Default3". The GetCookies method is used.
At this time, HttpWebResponse. Cookies only contain one Cookie, that is, Default3. That is, the Cookie generated on the last page.
In this way, when you automatically submit a form to crawl the page that requires Session or Cookie persistence, You need to upload the newly generated HttpWebResponse. the Cookie in Cookies is saved and cannot directly overwrite the previous Cookie value. Compare the Cookie values in HttpWebRequest. CookieContainer and HttpWebResponse. Cookies of each request to prevent any omission and cause some page crawling failure.
PS: I just figured it out. Maybe I have a deep understanding of it. I also hope that I can beat the bricks O ~