【问题标题】:Getting 401 unauthorized error in retrofit?在改造中出现 401 未经授权的错误?
【发布时间】:2016-01-30 16:13:07
【问题描述】:

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

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

【问题讨论】:

    标签: java android android-layout retrofit


    【解决方案1】:

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

    这是一篇关于如何在 Retrofit 中做到这一点的文章:https://futurestud.io/blog/android-basic-authentication-with-retrofit/

    【讨论】:

      猜你喜欢
      • 2020-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 2015-04-19
      相关资源
      最近更新 更多