You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The problem is duplication of cookies, which causes an endless Redirect. There are two CookieContainer. One is added to the RestClient.CookieContainer, along with the main cookies, and the second stores the cookies received when processing the Redirect or after the request is completed, according to this decision 2045#issuecomment-1500095598. The problem is that the first and second CookieContainer are added in turn to the request, which causes duplication.
var containerRequest = new CookieContainer();
var containerResponse = new CookieContainer();
var client = new RestClient(new RestClientOptions()
{
AutomaticDecompression = DecompressionMethods.All,
FollowRedirects = true,
MaxRedirects = 10,
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36",
BaseUrl = new Uri(url),
AllowMultipleDefaultParametersWithSameName = true,
RemoteCertificateValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; },
CookieContainer = containerRequest,
ConfigureMessageHandler = h =>
{
((HttpClientHandler)h).UseCookies = true;
((HttpClientHandler)h).CookieContainer = containerResponse;
return h;
}
});
Desktop (please complete the following information):
OS: Windows 10 Pro 22H2 19045.2846
.NET version .NET 6.0.16
Version 110.2.0
Additional context
At first I had one CookieContainer in RestClient and HttpClientHandler, but one of the users complained that he was always getting errors. When browsing through the http debugger, I found out that the cookies were duplicated, i.e. in the beginning there were cookies that were before the request, and then there were updated cookies, although the CookieContainer contained updated cookies.
Then I thought to put cookies only in HttpClientHandler, but with Redirect they were reset and it turned out that I was not authorized, if I put cookies only in RestClient.CookieContainer, then I will not receive cookies from the request and they will not be updated with Redirect.
The text was updated successfully, but these errors were encountered:
Well, you should either use the container for RestClient or for the message handler. If you use RestClient cookies, it handles stuff correctly. If you also use a custom container for the message handler - you will get these weird side effects.
At first I also used one container for everything, but this only duplicated the cookies (old + updated), so I decided to try with two containers and settled on this option, because. seemed like a better option.
Describe the bug
The problem is duplication of cookies, which causes an endless
Redirect
. There are twoCookieContainer
. One is added to theRestClient.CookieContainer
, along with the main cookies, and the second stores the cookies received when processing theRedirect
or after the request is completed, according to this decision 2045#issuecomment-1500095598. The problem is that the first and secondCookieContainer
are added in turn to the request, which causes duplication.Desktop (please complete the following information):
Additional context
At first I had one
CookieContainer
inRestClient
andHttpClientHandler
, but one of the users complained that he was always getting errors. When browsing through the http debugger, I found out that the cookies were duplicated, i.e. in the beginning there were cookies that were before the request, and then there were updated cookies, although theCookieContainer
contained updated cookies.Then I thought to put cookies only in
HttpClientHandler
, but withRedirect
they were reset and it turned out that I was not authorized, if I put cookies only inRestClient.CookieContainer
, then I will not receive cookies from the request and they will not be updated withRedirect
.The text was updated successfully, but these errors were encountered: