学技术学英语:http状态码 401 Unauthorized vs 403 Forbidden
📢📢📢:先看关键单词,再看英文,最后看中文总结,再回头看一遍英文原文,效果更佳!!
关键词
| unauthorized | 未授权的 | /ˌʌnˈɔːθəraɪzd/ |
| authentication | 认证 | /ɔːˌθentɪˈkeɪʃən/ |
| credentials | 凭证 | /krɪˈdenʃəlz/ |
| server | 服务器 | /ˈsɜːrvər/ |
| token | 令牌 | /ˈtəʊkən/ |
| expired | 过期的 | /ɪkˈspaɪərd/ |
| bearer | 持票人 | /ˈberər/ |
| forbidden | 禁止的 | /fərˈbɪdən/ |
| privileges | 特权 | /ˈprɪvɪlɪdʒɪz/ |
| authenticated | 经过身份验证的 | /ɔːˈθentɪkeɪtɪd/ |
| sufficient | 足够的 | /səˈfɪʃənt/ |
| irrespective | 无关的 | /ˌɪrɪˈspektɪv/ |
| integration | 集成 | /ˌɪntɪˈɡreɪʃən/ |
| adequate | 适当的 | /ˈædɪkwət/ |
| privileges | 特权 | /ˈprɪvɪlɪdʒɪz/ |
正文
401 Unauthorized vs 403 Forbidden
In web development, ensuring access control is essential in safely and efficiently managing APIs. The meanings of 401 Unauthorized and 403 Forbidden are sometimes confused. Nonetheless, both codes have to do with restricted resources, but they serve different purposes. In this article, we will explain the codes and instruct you on which one to use.
401 Unauthorized?
The response code for a request lacking valid authentication credentials from a client is referred to as the 401 Unauthorized status code. That being said, it means that before accessing the requested resource, it’s necessary for the server to authenticate itself to the client. If no credentials are provided or if wrong ones are given by the client, then what follows is a 401 status code.
When to Use 401 Unauthorized
Use 401 Unauthorized when:
- No authentication details have been received yet from the client.
- The authentication information supplied – username and password/token – is not valid/has expired.
- There is no authorization header present in your requests like “Authorization.”
For instance, if an API demands Bearer token for access but this token has not been included in any request or is incorrect it will issue back a response having HTTP-code of Unauthorized (the most common case).
403 Forbidden?
The reason for using a 403 Forbidden status code when the server recognizes the request, the client has been authenticated, but the client does not have permission to access the requested resource. It means that in this case, a client is known while a server intentionally turns down fulfilling his or her request because of inadequate privileges.
When to Use 403 Forbidden
Use 403 Forbidden when:
- Authenticated clientele lack sufficient permissions to reach given resources. • Server denies resource access irrespective of client’s authentication state. • Client’s access to resources is prohibited by any form of an access control system.
For instance, an authorized user may try accessing an admin only page without having adequate role. Even if one gets logged in and receive a response like ‘forbidden’ but still he/she does not have enough rights.
401 vs 403
| Aspect | 401 Unauthorized | 403 Forbidden |
|---|---|---|
| Purpose | 401 indicates missing or invalid authentication. | 403 indicates lack of permission despite valid authentication. |
| When should server send this? | When the client needs to provide valid credentials. | When the client is authenticated but not authorized to access the resource. |
| What should the client do on receiving this? | The client should provide or correct authentication details. | The client should not retry, as access is denied. |
| Example | Accessing a resource without a valid API token. | Accessing a restricted admin area without sufficient privileges. |
With the correct usage of 401 Unauthorized and 403 Forbidden status codes, you can make sure to avoid unwanted integration support tickets. The message clearly informs the clients on why they cannot gain access.
By correctly using 401 Unauthorized and 403 Forbidden status codes, you can ensure that your API communicates access issues clearly and helps clients understand the nature of the problem.
总结:
-
401 Unauthorized:
- 401 Unauthorized 状态码表示客户端请求缺少有效的身份验证凭证。
- 服务器需要在访问请求的资源之前对客户端进行身份验证。
- 如果客户端没有提供凭证或提供了错误的凭证,则返回401状态码。
- 使用场景:
- 客户端尚未提供任何身份验证详细信息。
- 提供的身份验证信息(如用户名和密码/令牌)无效或已过期。
- 请求中没有包含授权头(如“Authorization”)。
-
403 Forbidden:
- 403 Forbidden 状态码表示服务器识别了请求,客户端已通过身份验证,但客户端没有权限访问请求的资源。
- 服务器明确拒绝客户端的请求,因为权限不足。
- 使用场景:
- 经过身份验证的客户端缺乏足够的权限访问资源。
- 无论客户端的身份验证状态如何,服务器都拒绝资源访问。
- 访问控制系统禁止客户端访问资源。
具体来说,用户名/密码或者其他方式登录系统就会返回一个token, 后续请求请求头里的token无效那么服务端就会返回401, 如果token有效,但是该用户权限不足不能访问对应的资源就会返回403
相关文章:
学技术学英语:http状态码 401 Unauthorized vs 403 Forbidden
📢📢📢:先看关键单词,再看英文,最后看中文总结,再回头看一遍英文原文,效果更佳!! 关键词 unauthorized未授权的/ˌʌnˈɔːθəraɪzd/authentication认证/…...
@LocalBuilder装饰器: 维持组件父子关系
一、前言 当开发者使用Builder做引用数据传递时,会考虑组件的父子关系,使用了bind(this)之后,组件的父子关系和状态管理的父子关系并不一致。为了解决组件的父子关系和状态管理的父子关系保持一致的问题,引入LocalBuilder装饰器。…...
React(二)——Admin主页/Orders页面/Category页面
文章目录 项目地址一、侧边栏1.1 具体实现 二、Header2.1 实现 三、Orders页面3.1 分页和搜索3.2 点击箭头显示商家所有订单3.3 页码按钮以及分页 四、Category页面4.1 左侧商品添加栏目4.2 右侧商品上传栏 五、Sellers页面六、Payment Request 页面(百万数据加载&a…...
移动端屏幕分辨率rem,less
谷歌模拟器:能直接看到移动端效果 屏幕分辨率 右键电脑桌面 ,点击显示设置 PC端是逻辑分辨率,移动端代码也是参考逻辑分辨率 网页端宽度和逻辑分辨率尺寸相同 手机屏幕尺寸不同,网页宽度均为 100% 所以就需要添加视口标签&#x…...
Docker Desktop 构建java8基础镜像jdk安装配置失效解决
Docker Desktop 构建java8基础镜像jdk安装配置失效解决 文章目录 1.问题2.解决方法3.总结 1.问题 之前的好几篇文章中分享了在Linux(centOs上)和windows10上使用docker和docker Desktop环境构建java8的最小jre基础镜像,前几天我使用Docker Desktop环境重新构建了一个…...
数据结构:栈(Stack)和队列(Queue)—面试题(一)
目录 1、括号匹配 2、逆波兰表达式求值 3、栈的压入、弹出序列 4、最小栈 1、括号匹配 习题链接https://leetcode.cn/problems/valid-parentheses/description/ 描述: 给定一个只包括 (,),{,},[,] …...
AR 眼镜之-拍照/录像动效切换-实现方案
目录 📂 前言 AR 眼镜系统版本 拍照/录像动效切换 1. 🔱 技术方案 1.1 技术方案概述 1.2 实现方案 1)第一阶段动效 2)第二阶段动效 2. 💠 默认代码配置 2.1 XML 初始布局 2.2 监听滑动对 View 改变 3. ⚛️…...
2025年中科院分区大类划分公布!新增8155本
2025年中科院分区表变更情况 扩大收录范围 2025年的期刊分区表在原有的自然科学(SCIE)、社会科学(SSCI)和人文科学(AHCI)的基础上,增加了ESCI期刊的收录,并根据这些期刊的数据进行…...
S变换matlab实现
S变换函数 function [st,t,f] st(timeseries,minfreq,maxfreq,samplingrate,freqsamplingrate) % S变换 % Code by huasir Beijing 2025.1.10 % Reference is "Localization of the Complex Spectrum: The S Transform" % from IEEE Transactions on Signal Proc…...
Springboot——钉钉(站内)实现登录第三方应用
文章目录 前言准备1、创建钉钉应用,并开放网页应用2、配置网页应用各项参数发布版本 前端改造后端逻辑1、获取应用免登录 Access_token2、通过免登录 Access_token 和 Auth_Code 获取对应登录人信息 注意事项 前言 PC端的钉钉中工作台,增加第三方应用&a…...
基于深度学习算法的AI图像视觉检测
基于人工智能和深度学习方法的现代计算机视觉技术在过去10年里取得了显著进展。如今,它被广泛用于图像分类、人脸识别、图像中物体的识别等。那么什么是深度学习?深度学习是如何应用在视觉检测上的呢? 什么是深度学习? 深度学习是…...
cJson——序列化格式json和protobuf对比
cJson——序列化格式json和protobuf对比 1. 更小的消息体积2. 更快的序列化与反序列化速度3. 类型安全4. 向后和向前兼容性5. 更低的带宽消耗6. 高效的编码方式7. 易于跨语言支持8. 支持复杂的数据结构9. 更好的支持大型数据交换总结 Protocol Buffers (Protobuf) 和 JSON 都是…...
搭建一个fastapi的项目,调用ollama服务
1. 项目结构 my_project/ │ ├── app/ │ ├── main.py # FastAPI应用的入口 │ ├── services/ # 包含服务逻辑 │ │ └── ollama_service.py │ ├── models/ # 定义数据模型 │ │ └── response.py │ ├─…...
Wireshark编译手册(Windows)
以下是对 Wireshark 官方文档中“Windows 平台的设置和构建说明”部分的翻译和总结: 2.2. Windows 平台 本节提供了在 Windows 上进行 Wireshark 开发的快速设置指南,包含推荐的配置。 2.2.1. 使用 Microsoft Visual Studio 注意:除非您非…...
在高德地图上加载3DTilesLayer图层模型/天地瓦片
1. 引入必要的库 Three.js:一个用于创建和显示3D图形的JavaScript库。vuemap/three-layer:一个Vue插件,它允许你在高德地图中添加Three.js图层。vuemap/layer-3dtiles:一个用于处理3D Tiles格式数据的Vue插件,可以用来…...
深入浅出负载均衡:理解其原理并选择最适合你的实现方式
负载均衡是一种在多个计算资源(如服务器、CPU核心、网络链接等)之间分配工作负载的技术,旨在优化资源利用率、提高系统吞吐量和降低响应时间。负载均衡的实现方式多种多样,以下是几种常见的实现方式: 1. 硬件负载均衡&…...
STM32的存储结构
STM32F103 芯片是基于 ARM Cortex-M3 内核的微控制器,它集成了多种类型的存储器,每种存储器都有其特定的作用和存储对象。以下是关于 STM32F103 中 Flash、ROM 和 SRAM 的详细介绍: 1. Flash Memory (闪存) 作用:Flash 是非易失性…...
@SneakyThrows 注解详解
SneakyThrows 注解详解 1. 基本介绍 SneakyThrows 是 Lombok 提供的注解,用于简化异常处理,自动生成 try-catch 代码块,将检查型异常转换为非检查型异常。 2. 使用对比 2.1 传统写法 public String readFile(String path) {try {return …...
js监测页面可见性
监测切换页面 检测页面的可见性状态document.visibilityState:document.hiddenvisibilitychange 事件 js 检测页面切换至别的应用 检测页面的可见性状态 在JavaScript中,你可以使用Page Visibility API来检测页面的可见性状态。这个API提供了一组接口,允…...
Android wifi常见问题及分析
参考 Android Network/WiFi 那些事儿 前言 本文将讨论几个有意思的网络问题,同时介绍 Android 上常见WiFi 问题的分析思路。 网络基础Q & A 一. 网络分层缘由 分层想必大家很熟悉,是否想过为何需要这样分层? 网上大多都是介绍每一层…...
解锁Windows效率提升:免费工具Winhance-zh_CN全功能指南
解锁Windows效率提升:免费工具Winhance-zh_CN全功能指南 【免费下载链接】Winhance-zh_CN A Chinese version of Winhance. C# application designed to optimize and customize your Windows experience. 项目地址: https://gitcode.com/gh_mirrors/wi/Winhance-…...
ADC0809模数转换实战:如何用51单片机+LCD1602搭建简易电压表(附完整代码)
51单片机与ADC0809模数转换实战:打造高精度LCD电压表 1. 项目背景与核心器件解析 在电子测量领域,电压表是最基础也最常用的工具之一。传统指针式电压表虽然直观,但精度和功能扩展性有限。而基于51单片机与ADC0809的数字电压表,不…...
别再让AI瞎猜了!手把手教你为项目创建AGENTS.md文件(附Turbo monorepo实战模板)
别再让AI瞎猜了!手把手教你为项目创建AGENTS.md文件(附Turbo monorepo实战模板) "AI生成的代码又跑偏了!"——这可能是现代开发者最常遇到的挫败场景之一。当你在Turborepo管理的monorepo中工作时,AI助手可…...
8元和3元的降AI工具差在哪用数据说话
降AI率工具市场里,价格跨度很大:有3元/千字的,有8元/千字的,差了2.5倍。 很多同学的第一反应是"贵的肯定好",但这个逻辑在降AI工具领域不一定成立。这篇文章用实测数据说话,对比比话降AI&#x…...
TOAST UI Chart错误处理与调试终极指南:10个常见问题解决方案大全
TOAST UI Chart错误处理与调试终极指南:10个常见问题解决方案大全 【免费下载链接】tui.chart 🍞📊 Beautiful chart for data visualization. 项目地址: https://gitcode.com/gh_mirrors/tu/tui.chart TOAST UI Chart是一款功能强大的…...
收藏!小白程序员必看:轻松入门大模型核心概念MCP与Skill,解锁AI能力新姿势!
本文通过生活化比喻,深入浅出地解释了AI领域中的MCP和Skill两大核心概念。MCP如同AI世界的“USB接口”,是标准化的连接协议,让AI能调用外部工具;Skill则像“工作手册”,是工作规范/技能模板,告诉AI在不同场…...
TFLint Docker终极指南:在容器中轻松运行Terraform代码检查
TFLint Docker终极指南:在容器中轻松运行Terraform代码检查 【免费下载链接】tflint A Pluggable Terraform Linter 项目地址: https://gitcode.com/gh_mirrors/tf/tflint TFLint是一个可插拔的Terraform代码检查工具,帮助开发者发现Terraform配置…...
Hermes性能优化:如何提高邮件生成速度和降低资源消耗
Hermes性能优化:如何提高邮件生成速度和降低资源消耗 【免费下载链接】hermes Golang package that generates clean, responsive HTML e-mails for sending transactional mail 项目地址: https://gitcode.com/gh_mirrors/he/hermes Hermes是一个Golang包&a…...
系统级音频均衡器如何提升macOS音质:开源eqMac完全指南
系统级音频均衡器如何提升macOS音质:开源eqMac完全指南 【免费下载链接】eqMac macOS System-wide Audio Equalizer & Volume Mixer 🎧 项目地址: https://gitcode.com/gh_mirrors/eq/eqMac eqMac是一款开源的macOS系统级音频均衡器与音量混合…...
iOS激活锁终极绕过:3步解锁Apple设备完整指南
iOS激活锁终极绕过:3步解锁Apple设备完整指南 【免费下载链接】applera1n icloud bypass for ios 15-16 项目地址: https://gitcode.com/gh_mirrors/ap/applera1n 你是否曾经遇到过这样的情况:购买了一台二手iPhone,却发现它被原主人的…...
