簡體   English   中英

DioErrorType.RESPONSE 無效的媒體類型

[英]DioErrorType.RESPONSE invalid media type

我的 flutter 項目在 android 上運行良好,但是在嘗試將其安裝到 web 時我遇到了一些麻煩。 我正在使用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}]
║    }
╚══════════════════════════════════════════════════════════════════════════════════════════

下面是客戶端的外觀

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,
  );
}

任何解決此問題的評論/答案將不勝感激

這看起來像 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM