c# - HttpClient Not Saving Cookies -
i using new httpclient handle project's web surfing needs; however, although correctly set, httpclient not save cookies cookie container , empty.
code
private cookiecontainer _cookiecontainer = new cookiecontainer(); private httpclient httpclient { get; set; } private httpclienthandler httpclienthandler { get; set; } public initialize() { httpclienthandler = new httpclienthandler { allowautoredirect = true, usecookies = true, cookiecontainer = _cookiecontainer }; httpclient = new httpclient(httpclienthandler); } public cookiecontainer cookies { { return _cookiecontainer; } set { _cookiecontainer = value; } } public void test() { //this empty, although sure site saving login cookies var cookies = cookies; }
weird... did tried directly use httpclienthandler's cookiecontainer ?
code :
public initialize() { httpclienthandler = new httpclienthandler { allowautoredirect = true, usecookies = true, cookiecontainer = new cookiecontainer() }; httpclient = new httpclient(httpclienthandler); } public cookiecontainer cookies { { return httpclienthandler.cookiecontainer; } set { httpclienthandler.cookiecontainer = value; } }
Comments
Post a Comment