在改装中出现401未经授权的错误? [英] Getting 401 unauthorized error in retrofit?

查看:70
本文介绍了在改装中出现401未经授权的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误 401未经授权表示请求由于凭据无效而被拒绝.我正在使用改造请求到 https URL,并在执行 curl https://external:userName@api-staging.xyz.com/user时获得 401未经授权/get 对我来说非常理想(获得预期的输出).

Error 401 unauthorized means request is denied due to invalid credentials. I am making request to https URL using retrofit and getting 401 unauthorized while doing curl https://external:userName@api-staging.xyz.com/user/get it works perfectly for me (getting expected output).

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

There is nothing wrong with the Retrofit implementation in my application because other calls is working fine. Is that something that I cannot pass such URL to retrofit.setEndpoint?

推荐答案

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

It is possible that Retrofit does not support putting the username and password in the URL (due to security reasons). This kind of authentication is called Basic Authentication, and you can pass these parameters in an HTTP header as well.

这里有一篇文章介绍如何在翻新中实现: https://futurestud.io/blog/android-basic-authentication-with-retrofit/

Here's an article about how that can be done in Retrofit: https://futurestud.io/blog/android-basic-authentication-with-retrofit/

这篇关于在改装中出现401未经授权的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆