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

4 java android android-layout retrofit

错误401 unauthorized意味着请求由于凭据无效而被拒绝。我正在https使用改造向 URL 发出请求,并且401 unauthorized在执行curl https://external:userName@api-staging.xyz.com/user/get过程中对我来说非常有效(获得预期的输出)。

Retrofit我的实现没有任何问题,application因为其他调用工作正常。我无法将这样的 URL 传递给它吗retrofit.setEndpoint

Dan*_*nai 5

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

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