Skip to content
Advertisement

I want to add a bearer token to my retrofit post request

I have an app that is to register people into a platform but I get a response of Unauthenticated each time I submit the form data. The form is submitted using an API which requires a bearer token for each post request with the aid of retrofit. I have been out of touch with Java. Note: its just a plain form. No authentication has been implemented in the app.

My ApiClient.java class

JavaScript

My UserService.java class

JavaScript

My saveUser Method

JavaScript

My UserRequest

JavaScript

Advertisement

Answer

If you most of your https requests need authentication then the first answer is perfect but if some of your requests need then you can pass the header to each methods.

JavaScript

While calling the method simply pass your token along with userRequest.

Advertisement