Flutter REST API authentication method returns "400 Bad Request" error (with first letter capitalized)

323 Views Asked by At
static Future<RequestArray> requestQuotesListHistory(
      String url, Map bodyx) async {
    Map<String, String> _header = <String, String>{
      "Authorization": "Bearer $vToken",
    };
    try {
      print(_header);
      print(vToken);
      final response = await http.post(
        Uri.parse(url),
        headers: _header,
        
        body: bodyx,
      );
      if (200 == response.statusCode) {
        print(response.headers);
        var jsonString = response.body;
        print(jsonString);
        var jsonMap = json.decode(jsonString);
        print(jsonMap);
        var rqQuoteList = RequestArray();
        rqQuoteList = RequestArray.fromJson(jsonMap);
        return rqQuoteList;
      } else {
        return RequestArray();
      }
    } catch (e) {
      return RequestArray();
    }
  }

The issue is that I sent the authorization in a case-sensitive format, but when I made the API call, the response I received was the array shown below:

I/flutter (15684):
[user-agent] => Dart/2.19 (dart:io)
[content-type] => application/x-www-form-urlencoded; charset=utf-8
[accept-encoding] => gzip
[content-length] => 57
[authorization] => Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
[host] => api.ss.com
0

There are 0 best solutions below