Use HttpClientHandler with ODataClient

477 Views Asked by At

I have a custom HttpClientHandler class which inherits from HttpClientHandler and for most scenarios it is used with the HttpClient as var client = new HttpClient(new CustomHttpClientHandler()) and it is working fine but I have a case where instead of HttpClient I have ODataClient, so is there anyway I can use my httpclient handler with the ODataClient?

1

There are 1 best solutions below

0
On

Add OnApplyClientHandler to the ODataClientSettings:

public static ODataClient Client(Uri uri)
  {
    var credentials = CredentialCache.DefaultCredentials;
    var settings = new ODataClientSettings(uri, credentials)
    {
        OnTrace = (x, y) => Logger.Info(x, y),
        OnApplyClientHandler = ClientHandler
    };
    return new ODataClient(settings);
}

private static void ClientHandler(HttpClientHandler obj)
{ 
    obj.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
}