大佬教程收集整理的这篇文章主要介绍了DioErrorType.RESPONSE 无效媒体类型,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的 Flutter 项目在 androID 上运行良好,但是当我尝试将它放到 web 上时我遇到了一些麻烦。我使用 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,);
}
任何解决此问题的评论/答案将不胜感激
这看起来像是 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
以上是大佬教程为你收集整理的DioErrorType.RESPONSE 无效媒体类型全部内容,希望文章能够帮你解决DioErrorType.RESPONSE 无效媒体类型所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。