Public class WebClientHelper: WebClient
{
Public WebClientHelper () : this (new CookieContainer ())
{
}
Public WebClientHelper (CookieContainer c)
{
Enclosing CookieContainer=c;
}
Public CookieContainer CookieContainer {get; set; }
Protected override WebRequest GetWebRequest address (Uri)
{
WebRequest request=base. GetWebRequest (address);
If (request is HttpWebRequest)
{
(the request as HttpWebRequest). CookieContainer=this. CookieContainer;
}
Return the request;
}
///& lt; Summary>
///the url redirection after
///& lt;/summary>
Public string ServerUrl {get; set; }
Protected override WebResponse GetWebResponse (WebRequest request)
{
Var response=base. GetWebResponse (request);//when code execution here cookies have value, how to assign a value to a Cookie?
ServerUrl=response. ResponseUri. Authority;
Return to base. GetWebResponse (request);
}
Var response=base. GetWebResponse (request); When carried out this code cookies have value, how to assign a value to a Cookie
CodePudding user response:
GetWebResponse server will give the client the need of cookies, convenient authentication and so on.If you want to use the crawler, or unconventional way access to the server resources, the need to to set the cookie, bypass part of the operation, should be set before you send to specify request.
You have to understand this process
CodePudding user response: