首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DioErrorType.RESPONSE无效的媒体类型

DioErrorType.RESPONSE无效的媒体类型
EN

Stack Overflow用户
提问于 2021-03-09 15:04:45
回答 1查看 124关注 0票数 1

我的flutter项目在android上运行得很好,但当我试图把它放到web上时,我遇到了一些麻烦。我使用Graphql Faker作为伪后端,它在安卓系统上运行良好,但对于flutter web,它总是抛出以下错误

代码语言:javascript
复制
╔╣ Request ║ POST 
║  http://localhost:9002/graphql
╚══════════════════════════════════════════════════════════════════════════════════════════

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

下面是客户端的外观

代码语言:javascript
复制
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,
  );
}

如果您对此有任何意见或答复,我们将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2021-03-10 04:17:01

这看起来像是CORS错误,graphql-faker文档中有一节是关于cors的:

代码语言:javascript
复制
--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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66542252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档