Map<String,String> headers = {'Content-Type':'application/json','authorization':'Basic c3R1ZHlkb3RlOnN0dWR5ZG90ZTEyMw=='};
var response = await post(Urls.getToken,
headers: headers,
body: {"grant_type":"password","username":"******","password":"*****","scope":"offline_access"},
);
위와 같이 작성했는데 "application/json"에러가 났다 ..
왜지?? 분명 headers content-type으로 명시했는데 ...알고보니 body를 jsonEncode해줘야 한다.
import 'package:http/http.dart' as http;
import 'dart:convert';
Map<String,String> headers = {'Content-Type':'application/json','authorization':'Basic c3R1ZHlkb3RlOnN0dWR5ZG90ZTEyMw=='};
final msg = jsonEncode({"grant_type":"password","username":"******","password":"*****","scope":"offline_access"});
var response = await post(Urls.getToken,
headers: headers,
body: msg,
);