首页 > 解决方案 > 一些用户在 Flutter 上遇到 socketException

问题描述

为什么这总是让 SocketException 开启?有时它正在工作。我的代码上有什么吗?

如何找到确切的错误?

 class ApiProvider {

  final http.Client client;

  ApiProvider({HttpClient client}) : this.client = client ?? http.Client();

  Future<dynamic> sendBook(Map data) async {

    var responseJson;
    var uri = Uri.parse('$url');
    uri = uri.replace(queryParameters: data);

    try {
      final response = await http.post(uri);
      responseJson = _response(response);
      return responseJson;
    } on SocketException {
      //Is there any way to find what is this error?
      throw FetchDataException('Something Happening, Please try again!');
    }
  }

主要方法

void main() async {
  HttpOverrides.global = OBHttpOverrides();

标签: flutterdartflutter-http

解决方案


推荐阅读