title: Flutter: Connection closed while receiving data
body: <p>I'm calling post API, and sometimes I get the response from the server and sometimes I receive the exception <code>Connection closed while receiving data</code>. Request is same in both cases, and according to backend server logs, a response is sent but i didn't receive it.
  I have this issue both in simulator and actual device.</p>
  <pre><code>try {
    final result =
        await http.post(url, body: encodedBody, headers: apiHeader);
    Map&lt;String, dynamic&gt; response = json.decode(result.body);
  
    print(&quot;Response: $response&quot;);
  
    return response;
  } catch (error) {
    Map&lt;String, dynamic&gt; response = Map&lt;String, dynamic&gt;();
    response['success'] = false;
    response['message'] = error;
    return response;
  }
  </code></pre>