Using Refit with Factory and Proxy

Sometimes a webhost wants you to use a proxy to communicate via http with an API for example. If you use Refit in C# with Factory implementation you can use the following code:


services.AddRefitClient()
.ConfigureHttpClient(c => c.BaseAddress = new Uri(Configuration.GetValue("The name of the value in your appsettings.json")))
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler()
{
UseProxy = true,
Proxy = new WebProxy("http://yourProxyUrl:yourProxyPort", false),
PreAuthenticate = true,
UseDefaultCredentials = false
});

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert