简体   繁体   English

DioErrorType.RESPONSE 无效的媒体类型

[英]DioErrorType.RESPONSE invalid media type

My flutter project runs well on android but when trying to get it to web I get some troubles.我的 flutter 项目在 android 上运行良好,但是在尝试将其安装到 web 时我遇到了一些麻烦。 I am using Graphql Faker as fake backend and it works well for android but for flutter web it always throw below error我正在使用Graphql Faker作为假后端,它适用于 android 但对于 flutter Z2567A5EC9705EB7AC2C984033E06 它总是在下面抛出错误89DZ6

╔╣ 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任何解决此问题的评论/答案将不胜感激

This looks like a CORS error, the graphql-faker documentation has a section about cors:这看起来像 CORS 错误,graphql-faker 文档有一个关于 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 颤振:DioError [DioErrorType.response]:XMLHttpRequest 错误 - flutter: DioError [DioErrorType.response]: XMLHttpRequest error Flutter DioError [DioErrorType.response]:XMLHttpRequest 错误 - Flutter DioError [DioErrorType.response]: XMLHttpRequest error DioError [DioErrorType.RESPONSE]: Http 状态错误 [400] 异常 - DioError [DioErrorType.RESPONSE]: Http status error [400] Exception Flutter:DioError [DioErrorType.RESPONSE]:Http 状态错误 [500] - Flutter: DioError [DioErrorType.RESPONSE]: Http status error [500] DioError [DioErrorType.RESPONSE]:Http 状态错误 [500],为什么? - DioError [DioErrorType.RESPONSE]: Http status error [500], why? Flutter DioError [DioErrorType.RESPONSE]: Http 状态错误 [403] - Flutter DioError [DioErrorType.RESPONSE]: Http status error [403] Flutter Dio:DioError [DioErrorType.RESPONSE]:Http 状态错误 [429] - Flutter Dio : DioError [DioErrorType.RESPONSE]: Http status error [429] DioError [DioErrorType.response] Http 状态错误 [404] - flutter - DioError [DioErrorType.response] Http status error [404] - flutter 无法捕获 dioerror [dioerrortype.response]:http 状态错误 [statusCode] - Unable to catch dioerror [dioerrortype.response]: http status error [statusCode] DioError [DioErrorType.RESPONSE]: Http 状态错误 [405] [已解决] - DioError [DioErrorType.RESPONSE]: Http status error [405] [Solved]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM