Flutter http post 请求无响应

时间:2021-01-05 18:20:30

标签: android laravel apache flutter http

我正在尝试从我的 Flutter 移动应用程序向在 ionos 上托管的 laravel api 发出帖子请求。

我遇到的问题是,在一些安卓智能手机上,当提交表单时,有时进度加载器会无限加载而不显示错误,有时它会立即工作。

我增加了我的 Laravel 应用程序的活动超时 int .htaccess 文件

<ifModule mod_env.c>
  SetEnv KeepAlive On
  SetEnv KeepAliveTimeout 100
  SetEnv MaxKeepAliveRequests 500
</ifModule>

<ifModule mod_headers.c>
  Header unset Connection
  Header set Connection keep-alive

  Header unset Keep-Alive
  Header set Keep-Alive timeout=100,max=500
</ifModule>

但问题仍然存在,它在某些设备(最新的智能手机)上成功运行,有时在其他设备上运行不成功。

请帮帮我,我这两天就遇到了这个问题

flutter/dart 代码

sendHouse() async {
    String url = ServerConfigs.api_url + "/house";
    
    final Map<String, dynamic> house = new Map<String, dynamic>();
    house['name'] = name;
    house['img'] = image.path.split("/").last;
    List<int> imageBytes = image.readAsBytesSync();
    house['img64'] = Base64Codec().encode(imageBytes);
    house['lat'] = lat;
    house['lon'] = lon;
    
    final response = await http.post(url, headers: {
      'Accept': 'application/json',
      'Authorization': 'Bearer ' + ServerConfigs.bearer_token
    }, body: {
      "data": house
    });

    var data = await json.decode(response.body);
    if (response.statusCode == 200) {
      emitSuccess();
    } else {
      print(data);
      print(response.statusCode);
      emitFailure();
    }
  }

1 个答案:

答案 0 :(得分:0)

在上传之前,我已经在我的 dart 代码中为图像添加了压缩功能,它解决了。