You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, in this moment i am using "IHttpClientFactory" and all works fine.
I need to know if is possible this approach:
private const string clientName = "SOC";
-login auth (with cert x509)
public async Task Connect(string url) { HttpClient httpclient = clientFactory.CreateClient(clientName); var res = await httpclient!.GetAsync( Path.Combine( string.Format( "https://serverlogin.com/cgi_AUT2000/CAutInicio.cgi?reference={0}", url ) ) ); }
-Get info
public async Task GetInfo(HttpRequestMessage message) { message.RequestUri = new Uri("https://server2.com/cve_cgi/api/users/"); HttpClient httpclient = clientFactory.CreateClient(clientName); HttpResponseMessage? res = await httpclient!.SendAsync(message); }
This is DI:
services .AddHttpClient( "SOC", c => { c.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0"); } ) .ConfigurePrimaryHttpMessageHandler(() => { CookieContainer? cookieContainer = new(); HttpClientHandler? handler = new() { CookieContainer = cookieContainer }; handler.ClientCertificates.Add( DigitalCert.GetCert(context.Configuration) ); return handler; });
This methods works fine.
So, now i want use the Refit library. Is this possible?
I have problems because i dont knows how change the base address...
services .AddRefitClient<IInterface>() .ConfigureHttpClient(c => { c.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0"); c.BaseAddress = new Uri("https://server2.com/cve_cgi/api/users/"); }) .ConfigurePrimaryHttpMessageHandler(() => { CookieContainer? cookieContainer = new(); HttpClientHandler? handler = new() { CookieContainer = cookieContainer }; handler.ClientCertificates.Add( DigitalCert.GetCert(context.Configuration) ); return handler; });
Beta Was this translation helpful? Give feedback.
All reactions