【问题标题】:Flutter uses http to retrieve the background interface, error: FormatException: Invalid radix-10 numberFlutter使用http检索后台接口,报错:FormatException: Invalid radix-10 number
【发布时间】:2019-08-19 00:18:50
【问题描述】:

flutter中使用http获取后台数据,但调试控制台报FormatException: Invalid radix-10 number。为什么?

库已经引入,是最新版本 我还以为是界面不对。现在我把它改成了我可以访问的正确的。

_get() async{
    print(3);
    try {
      var uri =  Uri.http('https://short-msg-ms.juejin.im/v1/topicList/recommend?uid=&device_id=&token=&src=web','');
      var response = await http.get(uri);
      print(response);
    } catch (error) {
      print(error);
    }
  } 

错误结果:

I/flutter (3573): FormatException: Invalid radix-10 number

【问题讨论】:

标签: flutter


【解决方案1】:

您以错误的方式使用Uri.http()。请阅读:doc

例子:

// http://example.org/path?q=dart.
new Uri.http("example.org", "/path", { "q" : "dart" });

【讨论】:

    【解决方案2】:

    也许你可以试试dio 来获取它。

    --

    首先导入dio

    import 'package:dio/dio.dart';
    

    并将其添加到 pubspec.yaml

    dependencies:
      dio: ^1.0.13
    

    试试这个:

    _get() async{
        Dio dio = new Dio();
      Response response;
    
        try {
          response = await dio.get(
          "https://short-msg-ms.juejin.im/v1/topicList/recommend?uid=&device_id=&token=&src=web");
          print(response);
        } catch (e) {
          print(e);
        }
      } 
    

    【讨论】:

      猜你喜欢
      • 2018-12-29
      • 1970-01-01
      • 1970-01-01
      • 2021-05-30
      • 1970-01-01
      • 2020-05-08
      • 2021-04-07
      • 2011-05-23
      • 2021-06-11
      相关资源
      最近更新 更多