[C#] Init(flurl)

2021/11/16 12:39:53

本文主要是介绍[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 
            });
        }



这篇关于[C#] Init(flurl)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程