http - 一次只能登录 1 响应代码

标签 http

我正在编写一个只允许用户同时从 1 个客户端登录的系统。

因此: 如果用户在 Phone 1 上登录(使用访问 token 1)并且用户抓取 Phone 2 再次登录(生成访问 token 2),我系统上的下一个 API 将被调用并返回错误代码。

现在这个错误代码将是 401。

一旦客户端检测到 401 响应,用户将被发送回登录页面,并会显示一条警报,告知用户该帐户已从另一台设备访问。

401 是用于此的正确错误代码吗?

最佳答案

401 错误代码表示未授权。换句话说,如果用户尚未访问应用程序并使用无效凭据,将返回相同的错误。

我建议您使用 403 Forbidden:

403 FORBIDDEN The server understood the request but refuses to authorize it.

或者409冲突:

409 CONFLICT The request could not be completed due to a conflict with the current state of the target resource. This code is used in situations where the user might be able to resolve the conflict and resubmit the request.

关于http - 一次只能登录 1 响应代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45273490/

相关文章:

c++ - 尝试发送 GET 请求,同一地址收到 301

http - 从 Tornado 提供视频文件

java - 使用适用于 Android 的 Java 的 HTTP API 请求

javascript - Angular2 promise : How to use the response from Http Get

java - 如何将文件上传集成到 Spring Data REST 存储库中?

http - 最大 HTTP 数据包大小

http - URL中的参数和<form method ="get">有什么区别吗?

http - 如果我只使用 OpenID,我应该为 401 上的 WWW-Authenticate header 传递什么?

python - 如何使用 Python 在 ASP.Net 中调用回发

c# - 如何处理 http 500 错误?