title: Flutter http Post - StatusCode 401 - repetition of response
body: <p>I have some trouble with my Http Post Request in Flutter. I must connect to a PHP web service (using a header) and post some user/password info to get a response (here, user info).
  I believe I am near to the solution but I still get a <code>StatusCode 401</code> as response despite the fact that it works when I try with Postman (with same credentials).</p>
  
  <p>Here is the code of the function I call :</p>
  
  <pre><code>Future&lt;http.Response&gt; post() async {
  
    var url = "https://www.monadresse/login.php";
    String password = "xxx";
    String username = "yyy";
    //var bytes = utf8.encode("$username:$password");
    var bytes = "$username:$password";
    String userNameUser = "www";
    String passwordUser = "zzz";
    var passwordUserEncoded = base64.encode(utf8.encode(passwordUser));
  //var passwordUserEncoded = base64.encode(passwordUser);
    var headers = {
      "Authorization": "Basic $bytes",
      "Content-Type": "application/json",
    };
    var requestBody = json.encode({ 'user': userNameUser, 'password': passwordUserEncoded});
    print(headers);
    print(requestBody);
  
    final http.Response response = await http.post(
      url,
      body: requestBody,
      headers: headers,
    );
    if(response.statusCode == 200){
      var responseJson = json.decode(response.body);
      print(Utf8Codec().decode(response.bodyBytes));
  
      print("Body: " + responseJson);}
  
    print(bytes);
    print(passwordUserEncoded);
    print(response.statusCode);
    print("Fini");
  }
  </code></pre>
  
  <p>Another weird thing (read 'I don't understand')... I have added some prints to have an idea of what's happening and, as you can see hereunder, the 2 first prints (located before the request) are first printed twice and after that the 3 last prints are also repeated twice.</p>
  
  <pre><code>flutter: {Authorization: Basic yyy:xxx, Content-Type: application/json}
  flutter: {"user":"www","password":"zzz"}
  flutter: {Authorization: yyy:xxx, Content-Type: application/json}
  flutter: {"user":"www","password":"zzz}
  flutter: yyy:xxx
  flutter: zzz
  flutter: 401
  flutter: Fini
  flutter: yyy:xxx
  flutter: zzz
  flutter: 401
  flutter: Fini
  </code></pre>
  
  <p>As I don't find a solution on the net I very hope someone will help me.</p>