Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

android - Flutter http post request no response

I'm trying to make a post request from my flutter mobile application to a laravel api hosted on ionos.

The problem I encounter is that on some android smartphone, when the form is submitted, sometimes the progress loader load indefinitly without showing errors and sometimes it work imediately.

I have increased the alive time out int .htaccess file of my laravel app

<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>

But the problem persist, it work successfully on some devices (most recent smartphones) and not on other sometimes.

Please help me, I'm facing the issue since 2 days

The flutter/dart code

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've added compress functionnaly to image in my dart code before upload and it solved.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...