1

I try to connect flutter with django via flutters http. Requests in python using requests.post work fine and I receive the authentification token.

I changed the standart adress http://127.0.0.1:8000/ according to this post to http://10.0.2.2:8000 and but receive the error

Error: FormatException: //10.0.2.2:8000
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:49                       throw_
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 246:5                                  parse
dart-sdk/lib/core/uri.dart 1791:49                                                                 _makeHttpUri
dart-sdk/lib/core/uri.dart 1687:12                                                                 http
...

in

  final _tokenEndpoint = "/api-token-auth";
  var uri        = Uri.http(_base, _tokenEndpoint);
  final response = await http.post(uri,
      headers: <String, String>{
        'Content-Type': 'application/json; charset=UTF-8',
        'Access-Control-Allow-Origin': '*'
      },
      body: jsonEncode(<String, String>{
        'username': username,
        'password': password
      }));
Uwe.Schneider
  • 1,112
  • 1
  • 15
  • 28

0 Answers0