http send body and header in flutter code example
Example 1: flutter http.post headers
Future<dynamic> get(String url) async {
return http.post(url, headers: {"Authorization": "Some token"}).then(
(http.Response response) {
final int statusCode = response.statusCode;
LogUtils.d("====response ${response.body.toString()}");
if (statusCode < 200 || statusCode >= 400 || json == null) {
throw new ApiException(jsonDecode(response.body)["message"]);
}
return _decoder.convert(response.body);
});
}
Example 2: can we send raw json in get method in flutter
final queryParameters = {
'name': 'Bob',
'age': '87',
};
final uri = Uri.http('www.example.com', '/path', queryParameters);
final headers = {HttpHeaders.contentTypeHeader: 'application/json'};
final response = await http.get(uri, headers: headers);