Home > Enterprise >  Flutter: Send JSON body with dio package get request
Flutter: Send JSON body with dio package get request

Time:12-21

this API is working normal in postman however in flutter app its returning this

{"success": true, "rslt": []}

where "rslt" is empty.

here's my code

dynamic getData(dynamic token) {
dio.options.headers['Authorization'] = '$token';
return await dio.get<dynamic>('https://address',
    queryParameters: <String,dynamic>{'cn': 'iPhone_11', 'qt': '20', 'ct': 'Delhi'});
}

What am I doing wrong in this code?

CodePudding user response:

In postman, you have added body to GET request. Normally GET request should not have body. But there is no body in your request in Flutter.

CodePudding user response:

You pass data with parameters but need to pass in body section that was missing, you need to call like that as below


Map data = {'cn': 'iPhone_11', 'qt': '20', 'ct': 'Delhi'};
dynamic getData(dynamic token) {
dio.options.headers['Authorization'] = '$token';
return await dio.get<dynamic>('https://address',
    data: jsonEncode(data);
}

  • Related