1

making a call to a https endpoint with "Flurl library" (on my developing machine) i get an error so i added the "famous"

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; 

to skip the certificate validation.

This doesn't seem to work with Flurl (but works with another libraries like "RestSharp")

this is my code:

public async Task<object> MyMethod()
        {

            var client = new Url(baseUrl)
                                .AppendPathSegment(_endpoint)
                                .SetQueryParam("mbxId", 7)
                                .WithBasicAuth(username, password)
                                .WithHeader("cache-control", "no-cache")
                                .WithHeader("contenttype", "application/json; charset=utf-8")
                                .WithHeader("Accept", "text/html, application/xhtml+xml, image/jxr, */*");


            return await client.GetAsync();
        }

it works if before making the call i open "fiddler" and i confirm the message warning about the certificate issues (in that case works, if i don't open fiddler first, don't)

Does ServicePointManager.ServerCertificateValidationCallback have a global scope? why flurls doesn't take in account this configuration?

----UPDATED----

inner exception:

[System.Exception {Flurl.Http.FlurlHttpExceprion}] 

message:

   {"Security Error"} Request to https://demo.xxxxx.xxxxxxxxxxxxx.com:8181/dmlm4ws/ws/sessions/sessions?mbxId=7 failed. An error occurred while sending the request.

stack trace

   in Flurl.Http.Configuration.FlurlMessageHandler.<InnerSendAsync>d__2.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\Configuration\FlurlMessageHandler.cs:riga 59
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
   in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   in Flurl.Http.Configuration.FlurlMessageHandler.<SendAsync>d__1.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\Configuration\FlurlMessageHandler.cs:riga 31
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
   in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   in Flurl.Http.Configuration.FlurlMessageHandler.<SendAsync>d__1.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\Configuration\FlurlMessageHandler.cs:riga 43
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
   in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   in Flurl.Http.Configuration.FlurlMessageHandler.<SendAsync>d__1.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\Configuration\FlurlMessageHandler.cs:riga 47
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
   in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   in System.Net.Http.HttpClient.<FinishSendAsync>d__58.MoveNext()
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
   in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   in Flurl.Http.FlurlClient.<SendAsync>d__28.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\FlurlClient.cs:riga 202
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
   in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   in System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   in DLMN.DMLM.<PerformRequest>d__8.MoveNext() in C:\PROGETTI\Progetti\DMLM\DLMN\DLMN\DMLM.cs:riga 90
--- Fine traccia dello stack da posizione precedente dove è stata generata l'eccezione ---
   in System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   in System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   in Flurl.Http.HttpResponseMessageExtensions.<ReceiveJson>d__0`1.MoveNext() in C:\projects\flurl\src\Flurl.Http.Shared\HttpResponseMessageExtensions.cs:riga 26
pinale
  • 2,060
  • 6
  • 38
  • 72

1 Answers1

0

Checkout this solution here which solves the problem with DefaultHttpClientFactory by overriding the CreateMessageHandler

public override HttpMessageHandler CreateMessageHandler() {
        return new HttpClientHandler {
            ServerCertificateCustomValidationCallback = (a, b, c, d) => true
        };
    }
wsduho
  • 377
  • 3
  • 9