Languages

Menu
Sites
Language
net HttpClientHandler size limit

Update after further investigations : Seems to have a size limit ??

Hello, I need in my app to retrieve a webpage. It seems like if the destination webpage is more than around 4kb it does not work anymore :(


HttpClient CreateHttpClient()
            {
                var ch = new HttpClientHandler
                {
                    CookieContainer = new CookieContainer(),
                    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
                    AllowAutoRedirect = false,
                    UseCookies = true,
                    
            };

                var client = new HttpClient(ch)
                {
                    BaseAddress = new Uri("https://auth.tesla.com"),
                    DefaultRequestHeaders =
                {
                    ConnectionClose = false,
                    Accept = { new MediaTypeWithQualityHeaderValue("application/json") },
                }
                };
                client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);

                return client;
            }

            HttpClient thisClient = CreateHttpClient();
            
            var b = new UriBuilder(thisClient.BaseAddress + "/oauth2/v3/authorize") { Port = -1 };

            var q = HttpUtility.ParseQueryString(b.Query);
            q["client_id"] = "ownerapi";
            q["code_challenge"] = codeChallenge;
            q["code_challenge_method"] = "S256";
            q["redirect_uri"] = "https://auth.tesla.com/void/callback";
            q["response_type"] = "code";
            q["scope"] = "openid email offline_access";
            q["state"] = state;
            b.Query = q.ToString();
            string url = b.ToString();
            Log.Debug(url);
            
            
            HttpResponseMessage result = thisClient.GetAsync(url).Result;
            resultContent = result.Content.ReadAsStringAsync().Result;

 

 

 

Edited by: Gaetan COLOMBIER on 02 May, 2021