[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
});
}
标签:Redirects,settings,C#,default,Init,handler,flurl,new,true 来源: https://www.cnblogs.com/yzpopulation/p/15560542.html