Login on another page/server #1561
sergioocode
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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