安全使用 HTTPS
使用 TLS 发出加密请求
安全使用 HTTPS 是 CoddyKit 上的免费 Arduino & IoT Academy 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Arduino & IoT Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Arduino & IoT Academy 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Plain HTTP Is Open
Regular HTTP sends everything in the clear. Anyone on the path can read your data, including any tokens or passwords. 🔓
HTTPS Adds Encryption
HTTPS wraps your request in TLS encryption. Snoopers see only scrambled bytes, not your readings or credentials.
It Also Proves Identity
HTTPS does more than hide data. It checks the server is the real one using a certificate, so you are not fooled by an impostor.
Use a Secure Client
On ESP32 you swap the plain client for a WiFiClientSecure. This is the object that speaks TLS for you.
#include <WiFiClientSecure.h>
WiFiClientSecure client;Point to an HTTPS URL
Pass the secure client and an https URL to begin(). The s in https is what triggers the encrypted path.
http.begin(client, "https://api.example.com/data");Trust the Right Server
To verify identity, give the client the server's root certificate. The board uses it to confirm the connection is genuine.
client.setCACert(rootCA);Avoid setInsecure
Calling setInsecure() skips certificate checks. It is handy for a quick test but unsafe for any real, shipped device.
client.setInsecure(); // testing onlyKeep the Clock Correct
Certificate checks compare dates, so your device needs the right time. Sync it with NTP or validation may fail.
TLS Costs Resources
Encryption uses extra memory and CPU. Reuse a connection where you can instead of opening a fresh TLS handshake each time.
Never Hardcode Secrets
HTTPS protects data in transit, not secrets baked into your code. Keep API keys out of plain source and out of public repos.
Default to Secure
For anything leaving your home network, prefer HTTPS. Treat plain HTTP as fine only for quick local experiments.
Quick Check
What does HTTPS give you that plain HTTP does not?
Recap
You switched to a WiFiClientSecure, used https URLs, verified the server with a root certificate, kept the clock right, and guarded your secrets. 🎉
常见问题解答
「安全使用 HTTPS」课时是免费的吗?
是的 — 「安全使用 HTTPS」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Arduino & IoT Academy 课程的其余内容,请升级到 CoddyKit PRO。 Arduino & IoT Academy 课程共包含 4 节课。
「安全使用 HTTPS」这节课中我会学到什么?
使用 TLS 发出加密请求 你通过在浏览器中直接运行的动手代码来练习 Arduino & IoT Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Arduino & IoT Academy 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Arduino & IoT Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「安全使用 HTTPS」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Arduino & IoT Academy 课中编写并运行代码吗?
能。每节 Arduino & IoT Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 从 API 获取 GET 数据
- POST 传感器读数
- 解析 JSON 响应
- 安全使用 HTTPS