401 Unauthorized error in retrofit?
Error 401 unauthorized
indicates that the request was rejected due to invalid credentials. I’m using the makeover to make a request to the https
URL and get
It works perfectly for me (getting the expected output).a 401 unauthorized
/get when executing curl https://external:[email protected]/user
There is nothing wrong with the Retrofit
implementation in my application
because the other calls work fine. Is this something I can’t pass such a URL to retrofit.setEndpoint
?
Solution
Retrofit may not support putting usernames and passwords in URLs (for security reasons).
This authentication is called basic authentication, and you can also pass these parameters in the HTTP header.
Here’s an article on how to do this in Retrofit: https://futurestud.io/blog/android-basic-authentication-with-retrofit/