- 直接上代码。
当然这里你需要先再
flutter
项目中pubspec.yaml
引入dio
···
dependencies:
flutter:
sdk: flutter
dio: ^2.1.7
···
import 'package:dio/dio.dart';
void main () {
void requestData () async {
Options options = Options(headers:
{HttpHeaders.authorizationHeader:" Bearer <your authorization code>"});
Response response = await Dio().get(<your url address>, options: options);
print(response);
}
}
这样就可以做请求了,这里authorization
是很多大厂的api
都需要设置的api key
。
希望能帮助到大家 ;)