http库地址
http | Dart Package

一、安装

With Dart:

$ dart pub add http

With Flutter:

$ flutter pub add http

This will add a line like this to your package’s pubspec.yaml (and run an implicit dart pub get):

dependencies: http: ^0.13.4

Import it

Now in your Dart code, you can use:

import ‘package:http/http.dart’;

二、使用

image.png

  1. import 'package:http/http.dart' as http;
  2. var url = Uri.parse('https://example.com/whatsit/create');
  3. var response = await http.post(url, body: {'name': 'doodle', 'color': 'blue'});
  4. print('Response status: ${response.statusCode}');
  5. print('Response body: ${response.body}');
  6. print(await http.read(Uri.parse('https://example.com/foobar.txt')));