Android flutter http请求

Android flutter http请求

1. pubspec.yaml

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

  http: ^0.12.1

2. lib代码

main.dart

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

void main() async {
  var client = http.Client();
  var url = 'http://www.baidu.com';
  try  {
    var uriResponse = await client.get(url);
    print(uriResponse.body);
  } finally {
    client.close();
  }
}

参考链接:
https://pub.dev/packages/http#-readme-tab-

你可能感兴趣的:(android)