Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Futter Getx GetConnect Post Request Responding into 401 Error

$
0
0

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:

enter image description here


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>