I am trying developing a Flutter app using Getx
state management. I am extending and implementing GetConnect
and GetxService
respectively in my APIClient calss. I am getting perfect result in Postman
but getting 401
error while requesting from the app. The app is sending the Authorization
Bearer token without issue.
Please, help me find out where it is going wrong and the solution.
I need to post form-data that's why I have created a Header
_mainHeaders = ({'content-type': 'multipart/form-data','Authorization': 'Bearer $token', });
I am sending a FormData
as body using Getx GetConnect
class. The FormData body is:
FormData formData = FormData({'name': name,'email': email,'phoneNumber': phoneNumber,'description': description });
Here is the post method:
Future<Response> postData(String uri, dynamic body) async { try { Response response = await post(uri, body, headers: _mainHeaders); return response; } catch (e) { return Response(statusCode: 1, statusText: e.toString()); } }
When I test in Postman
, I get the desired response. The postman form-data as follows: