title: flutter http.post is giving 500 error, while the api is working fine in postman
body: <p>This login API is working fine in postman, but I am getting <strong>500</strong> status code error in flutter. </p>
  
  <p>Below is the code for service where api being called:</p>
  
  <pre><code>import 'dart:convert';
  import 'package:http/http.dart' as http;
  ...
  
  class AuthService {
    static const API_URL =
        "http://ec2-15-185-73-129.me-south-1.compute.amazonaws.com";
    static const headers = {
      'Content-Type': 'application/json'
    };
    Future&lt;APIResponse&lt;AuthResponse&gt;&gt; signIn() async {
      var body = jsonEncode({"username": "username", "password": "password"});
      var response =
          await http.post(API_URL + "/api-token-auth", headers: headers, body: body)));
      print(response.body.toString());
      print(response.request.toString());
      if (response.statusCode == 200) {
        // not reaching here
      } else {
        print(handleError(response.statusCode));
        // response.statusCode is **500**
  
      }
    }
  }
  
  </code></pre>
  
  <p>print(response.body.toString()) gives below output:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  I/flutter ( 6158): &lt;html lang="en"&gt;
  I/flutter ( 6158): &lt;head&gt;
  I/flutter ( 6158):   &lt;meta http-equiv="content-type" content="text/html; charset=utf-8"&gt;
  I/flutter ( 6158):   &lt;meta name="robots" content="NONE,NOARCHIVE"&gt;
  I/flutter ( 6158):   &lt;title&gt;RuntimeError
  I/flutter ( 6158):           at /api-token-auth&lt;/title&gt;
  I/flutter ( 6158):   &lt;style type="text/css"&gt;
  I/flutter ( 6158):     html * { padding:0; margin:0; }
  I/flutter ( 6158):     body * { padding:10px 20px; }
  I/flutter ( 6158):     body * * { padding:0; }
  I/flutter ( 6158):     body { font:small sans-serif; background-color:#fff; color:#000; }
  I/flutter ( 6158):     body&gt;div { border-bottom:1px solid #ddd; }
  I/flutter ( 6158):     h1 { font-weight:normal; }
  I/flutter ( 6158):     h2 { margin-bottom:.8em; }
  I/flutter ( 6158):     h3 { margin:1em 0 .5em 0; }
  I/flutter ( 6158):     h4 { margin:0 0 .5em 0; font-weight: normal; }
  I/flutter ( 6158):     code, pre { font-size: 100%; white-space: pre-wrap; }
  I/flutter ( 6158):     table { border:1px solid #ccc; border-collapse: collapse; width:100%; background:white; }
  I/flutter ( 6158):     tbody td, tbody th { vertical-align:top; padding:2px 3px; }
  I/flutter ( 6158):     thead th {
  I/flutter ( 6158):       padding:1px 6px 1px 3px; background:#fefefe; text-align:left;
  I/flutter ( 6158):       font-weight:normal; font-size:11px; border:1px solid #ddd;
  I/flutter ( 6158):     }
  I/flutter ( 6158):     tbody th { width:12em; text-align:right; colo
  
  </code></pre>
  
  <p>print(response.request.toString()) gives below output:</p>
  
  <pre><code>POST http://ec2-15-185-73-129.me-south-1.compute.amazonaws.com/api-token-auth
  </code></pre>
  
  <p>Please help
  <a href="https://i.stack.imgur.com/OKNvY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OKNvY.png" alt="Postman request output"></a></p>