P
Size: a a a
P
AK
d
import 'package:http/http.dart' as http;
import './jwt';
class AuthenticatedHttpClient extends http.BaseClient {
@override
Future<http.StreamedResponse> send(http.BaseRequest request) async {
// intercept each call and add the Authorization header if token is available
final authToken = jwt.getJWT();
request.headers.putIfAbsent('Authorization', () => authToken);
request.headers.putIfAbsent('Content-type', () => 'application/json');
return request.send();
}
}
AuthenticatedHttpClient httpClient = AuthenticatedHttpClient();
// это надо обернуть в метод, чтобы декодировать json в одном месте и возвращался json body
final response = await httpClient.get(Uri.http('localhost:1337', 'api/v1/user/'));
// делаем так потому что кодировка слетит если кириллица
final body = json.decode(utf8.decode(response.bodyBytes));
KK
У
AK
AK
d
import 'package:http/http.dart' as http;
import './jwt';
class AuthenticatedHttpClient extends http.BaseClient {
@override
Future<http.StreamedResponse> send(http.BaseRequest request) async {
// intercept each call and add the Authorization header if token is available
final authToken = jwt.getJWT();
request.headers.putIfAbsent('Authorization', () => authToken);
request.headers.putIfAbsent('Content-type', () => 'application/json');
return request.send();
}
}
AuthenticatedHttpClient httpClient = AuthenticatedHttpClient();
// это надо обернуть в метод, чтобы декодировать json в одном месте и возвращался json body
final response = await httpClient.get(Uri.http('localhost:1337', 'api/v1/user/'));
// делаем так потому что кодировка слетит если кириллица
final body = json.decode(utf8.decode(response.bodyBytes));
AK
AK
Ю
AK
™
Ю
n_
Ю
P
P
P
У