[C#] Init(flurl)

flurl

    internal class CustomHttpClientFactory : DefaultHttpClientFactory
    {
        public override HttpMessageHandler CreateMessageHandler()
        {
            var handler = (HttpClientHandler) base.CreateMessageHandler();
            handler.UseCookies = true;
            handler.CookieContainer = new CookieContainer();
            handler.UseProxy = true;
            handler.Proxy = new WebProxy("http://127.0.0.1:8080");
            handler.ServerCertificateCustomValidationCallback = (_, _, _, _) => true;
            return handler;
        }

        public override HttpClient CreateHttpClient(HttpMessageHandler handler)
        {
            var httpClient = base.CreateHttpClient(handler);
            httpClient.DefaultRequestHeaders.ExpectContinue = false;
            return httpClient;
        }
    }
        static void Main(string[] args)
        {
            Bogus.DataSets.Internet internet = new Bogus.DataSets.Internet();
            FlurlHttp.Configure(settings => {
                var jsonSettings = new Newtonsoft.Json.JsonSerializerSettings
                {
                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
                    ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace
                };
                settings.JsonSerializer = new NewtonsoftJsonSerializer(jsonSettings);
                settings.HttpClientFactory = new CustomHttpClientFactory();
                settings.Timeout=TimeSpan.FromSeconds(5);
                settings.Redirects.Enabled = true; // default true
                settings.Redirects.AllowSecureToInsecure = true; // default false
                settings.Redirects.ForwardAuthorizationHeader = true; // default false
                settings.Redirects.MaxAutoRedirects = 5; // default 10 
            });
        }

上一篇:【随记】Dialog dismiss无法正常关闭问题


下一篇:python3 使用反射的编程思想,加强代码的扩展性