43 lines
1.3 KiB
Dart
43 lines
1.3 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:http/http.dart';
|
|
|
|
class CustomRequesterClient extends BaseClient {
|
|
final Client client = Client();
|
|
@override
|
|
Future<StreamedResponse> send(BaseRequest request) {
|
|
var information = GlobalInformation.getInstance();
|
|
if (information.token.isNotEmpty){
|
|
request.headers.addAll({"Authorization": information.token});
|
|
}
|
|
if (request.headers['Content-Type'] == 'text/plain; charset=utf-8'){
|
|
request.headers['Content-Type'] = "application/json";
|
|
}
|
|
return client.send(request);
|
|
}
|
|
}
|
|
class GlobalInformation {
|
|
static final GlobalInformation instance = GlobalInformation();
|
|
static final Uri baseUri = Uri.parse("http://124.93.196.45:10091/Neusoft/times-model/");
|
|
String token = "";
|
|
final Client requester = CustomRequesterClient();
|
|
static GlobalInformation getInstance(){
|
|
return GlobalInformation.instance;
|
|
}
|
|
}
|
|
|
|
Uri resolve(String url){
|
|
if (url.startsWith("/")){
|
|
url = url.substring(1);
|
|
}
|
|
return GlobalInformation.baseUri.resolve(url);
|
|
}
|
|
|
|
dynamic jsonFromResponse(Response response) {
|
|
var str = utf8.decode(response.bodyBytes);
|
|
return jsonDecode(str);
|
|
}
|
|
dynamic jsonFromStreamResponse(StreamedResponse response) async {
|
|
var str = utf8.decode(await response.stream.toBytes());
|
|
return jsonDecode(str);
|
|
} |