• [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 
                });
            }
    
    
  • 相关阅读:
    配置sqlserver端口
    HTML5本地存储之localStorage
    初始化ArrayList的方法
    like 模糊查询 mybatis写法
    关于删除 值的引用 导致入参丢失的问题。
    学生做题分析功能设计(正确率,已做)
    关于商城类项目 商品表如何设计的问题
    修改Mysql的自增Id
    java list转map的几种方式
    jxls 入门及几个比较坑的地方
  • 原文地址:https://www.cnblogs.com/yzpopulation/p/15560542.html
Copyright © 2020-2023  润新知