我的颤振项目在 android 上运行良好,但是在尝试将其发布到网络时我遇到了一些麻烦。我正在使用Graphql Faker作为假后端,它适用于 android,但对于 Flutter Web,它总是抛出错误
╔╣ 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,
);
}
任何解决此问题的评论/答案将不胜感激