Created
March 25, 2021 06:03
-
-
Save siteslave/0595b06ff2e44c01c4371ea6e09cd0f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'package:dio/dio.dart'; | |
String baseUrl = 'https://xxx.com/api'; | |
Dio dio = new Dio(new BaseOptions( | |
baseUrl: baseUrl, | |
receiveDataWhenStatusError: true, | |
connectTimeout: 60 * 1000, | |
receiveTimeout: 60 * 1000)); | |
class Api { | |
Api() { | |
dio.interceptors.add(PrettyDioLogger( | |
requestHeader: true, | |
requestBody: true, | |
responseBody: true, | |
responseHeader: false, | |
compact: true, | |
)); | |
} | |
Future<Response> loginCheck(String username, String password) async { | |
String path = '/login'; | |
return await dio | |
.post(path, data: {"username": username, "password": password}); | |
} | |
Future<Response> getDN(String token) async { | |
String path = '/xxx?xx=xxx'; | |
return await dio.get(path, | |
options: Options( | |
headers: {HttpHeaders.authorizationHeader: 'Bearer $token'})); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment