在改造中出现 401 未经授权的错误?

Getting 401 unauthorized error in retrofit?

错误401 unauthorized 表示请求因凭据无效而被拒绝。我正在请求 https URL 使用改造并在执行 curl https://external:userName@api-staging.xyz.com/user/get 时获得 401 unauthorized 它对我来说非常有效(获得预期的输出)。

我的 application 中的 Retrofit 实现没有任何问题,因为其他调用工作正常。那是我不能将 URL 传递给 retrofit.setEndpoint 的东西吗?

Retrofit 可能不支持将用户名和密码放在 URL 中(出于安全原因)。 这种身份验证称为基本身份验证,您也可以在 HTTP header 中传递这些参数。

这是一篇关于如何在 Retrofit 中完成此操作的文章:https://futurestud.io/blog/android-basic-authentication-with-retrofit/