DioErrorType.RESPONSE invalid media type

183

This looks like a CORS error, the graphql-faker documentation has a section about cors:

--cors-origin CORS: Specify the custom origin for the Access-Control-Allow-Origin header, by default it is the same as Origin header from the request
Share:
183
Nux
Author by

Nux

//Todo add about me

Updated on December 01, 2022

Comments

  • Nux
    Nux over 1 year

    My flutter project runs well on android but when trying to get it to web I get some troubles. I am using Graphql Faker as fake backend and it works well for android but for flutter web it always throw below error

    ╔╣ Request ║ POST 
    ║  http://localhost:9002/graphql
    ╚══════════════════════════════════════════════════════════════════════════════════════════
    
    ╔╣ DioError ║ Status: 500 Internal Server Error
    ║  http://localhost:9002/graphql
    ╚══════════════════════════════════════════════════════════════════════════════════════════
    ╔ DioErrorType.RESPONSE
    ║    {
    ║         errors: [{message: invalid media type}]
    ║    }
    ╚══════════════════════════════════════════════════════════════════════════════════════════
    

    Below is how client looks

    GraphQLClient graphQLClient()  {
      final dio = Dio(
        BaseOptions(
          connectTimeout: 3 * 1000,
          contentType: 'application/json',
        ),
      );
    
      final host = () {
        try {
          if (Platform.isAndroid) return MY_IP;
        } catch (_) {}
        return 'localhost';
      }();
    
      final graphqlEndpoint = 'http://$host:9002/graphql';
      final WebSocketLink _wsLink = WebSocketLink('ws://$host:4000/graphql');
    
      final Link _dioLink = DioLink(
        graphqlEndpoint,
        client: dio,
      );
    
      // split request based on type
      final _link = Link.split(
        (request) => request.isSubscription,
        _wsLink,
        _dioLink,
      );
    
      return GraphQLClient(
        cache: GraphQLCache(),
        link: _link,
      );
    }
    

    Any comment/answer to fix this will be appreciated

  • Nux
    Nux about 3 years
    The problem is with dio and dioLink since they send muliple content headers. It has been reported here github.com/TarekkMA/gql_dio_link/issues/4