[목적]
대부분의 web service에서 authorization을 부여해야 함.
HTTP Header에서 Authorization을 주는 방법 알기
[방법]
http package에서 header에 추가하는 손쉬운 방법을 제공함
[예시]
Future<Album> fetchAlbum() async {
final response = await http.get(
Uri.parse('https://jsonplaceholder.typicode.com/albums/1'),
headers: {
httpHeaders.authorizationHeader: 'Basic your_api_token_here',
},
);
final responseJson = jsonDecode(response.body);
return Album.fromJson(responseJson);
}
'Application > Flutter' 카테고리의 다른 글
[Cookbook] Internet에서 데이터 가져오기 (0) | 2022.08.03 |
---|---|
[Widget] TabBar, TabBarView (0) | 2022.07.26 |
[Cookbook] Background에서 JSON parsing 하는 방법 (0) | 2022.07.25 |
[Cookbook] Networking - 데이터 삭제 (0) | 2022.07.20 |
Flutter Widget Document (0) | 2022.07.20 |