Giter Club home page Giter Club logo

Comments (2)

rose-a avatar rose-a commented on September 26, 2024

We've seen limitations at this point before (in earlier cases with WASM, see https://github.com/graphql-dotnet/graphql-client#blazor-webassembly-limitations).

Could you try to find out what type Options.HttpMessageHandler actually is in your app (because it obviously isn't of type HttpClientHandler or derived from it)?

from graphql-client.

adlartuten avatar adlartuten commented on September 26, 2024

Ah, I definitely see my issue here now. My MessageHandler is a custom class in order to get around SSL when using the Android emulator for testing. It was the best solution I found for MAUI testing when connecting to localhost:
dotnet/maui#8131
https://gist.github.com/Eilon/49e3c5216abfa3eba81e453d45cba2d4

The code I'm using looks like this:

public GraphQLHttpClient Client { get; set; }

var options = new GraphQLHttpClientOptions { HttpMessageHandler = GetInsecureHandler(), EndPoint = new Uri(endpoint) };
Client = new GraphQLHttpClient(options, new NewtonsoftJsonSerializer());

public HttpMessageHandler GetInsecureHandler()
{
    var handler = new CustomAndroidMessageHandler();
    handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =>
    {
        if (cert.Issuer.Equals("CN=localhost")) return true;
        return errors == System.Net.Security.SslPolicyErrors.None;
    };
    return handler;
}

internal sealed class CustomAndroidMessageHandler : Xamarin.Android.Net.AndroidMessageHandler
{
    protected override Javax.Net.Ssl.IHostnameVerifier GetSSLHostnameVerifier(Javax.Net.Ssl.HttpsURLConnection connection)
        => new CustomHostnameVerifier();

    private sealed class CustomHostnameVerifier : Java.Lang.Object, Javax.Net.Ssl.IHostnameVerifier
    {
        public bool Verify(string? hostname, Javax.Net.Ssl.ISSLSession? session)
        {
            return
                Javax.Net.Ssl.HttpsURLConnection.DefaultHostnameVerifier.Verify(hostname, session)
                || hostname == "10.0.2.2" && session.PeerPrincipal?.Name == "CN=localhost";
        }
    }
}

I am honestly not very familiar with SSL connections and backend development in general, could this solution be modified to be compatible? Or would the better option just be to somehow get a valid SSL certificate set up on the Android emulator?

Thank you so much for your patience and help!

from graphql-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.