Skip to content

Instantly share code, notes, and snippets.

@siteslave
Created March 25, 2021 06:03
Show Gist options
  • Save siteslave/0595b06ff2e44c01c4371ea6e09cd0f1 to your computer and use it in GitHub Desktop.
Save siteslave/0595b06ff2e44c01c4371ea6e09cd0f1 to your computer and use it in GitHub Desktop.
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