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

Categories

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

http - Flutter REST Calls Time Out

I am making api calls via flutter to my server. I have checked my android manifest settings and I have placed

 <uses-permission android:name="android.permission.INTERNET"/>   

But, the api calls time out. Here is my call:

Future driverLogin(userdetails) async {
  var url = 'http://$_server/api/token/';

  print(userdetails.values);

  await http.post(url, body: json.encode(userdetails), headers: {
    "Content-Type": "application/json"
  }).then((http.Response response) {
    print(response.body);
    final Map<String, dynamic> responseData = json.decode(response.body);

    Token tkn = Token.fromJSON(responseData);

    _accessTkn = tkn.access;
    _refreshTkn = tkn.refresh;
    print('Refreshingly refreshed ${tkn.refresh}');

    if (response.statusCode == 200) {
      addToken(_accessTkn);
      addRefresh(_refreshTkn);

      print(responseData);
      // tokenType = 'email';

      print('Signed In');
      // preformLogin();
    } else {
      // popupSwitch(2);
      print('Error Could not sign in');
    }
  });
  return _accessTkn;
}

 

When I run it I get this error:

Bad state: Insecure HTTP is not allowed by platform:


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

1 Answer

0 votes
by (71.8m points)

make sure to import like this.

import 'package:http/http.dart' as http;

and make your url like this.

var url = 'https://$_server/api/token/';

Also check this links maybe will help you

https://flutter.dev/docs/release/breaking-changes/network-policy-ios-android https://medium.com/flutter-community/solving-the-new-https-requirements-in-flutter-7abe240fbf23


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...