没什么可说的就是开发中需要做https请求,但是几乎没有找到例子。最后就研究开源代码头文件、等文档。
实现了https请求。
一、基本使用方法
看到过一个博客用的#include <WiFiClientSecure.h>但是那个封装有问题。请求返回特别慢。
后来看到NodeMCU有自己的https实现。使用起来特别顺滑。特地献上一篇博客。
这是NodeMCU开源代码中关于网络请求的源代码头文件:
https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h
再开发NodeMCU的时候遇到问题没有解决方案,就要看源码了。
示例代码:
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
//定义全局量
const char* ssid = "xxxx"; //替换你的ssid
const char* password = "123456";//替换你的密码
//https configs
const char* host = "api.xxx.org"; //填写你自己的域名
const int httpsPort = 443; //这是https请求标准端口
// Use web browser to view and copy
// SHA1 fingerprint of the certificate
//把你需要调用的请求地址用浏览器访问,然后打开调试工具选择“安全”即可看到对应请求的fingerprint,复制到这个地方即可
const char* fingerprint = "CB E2 9A F0 0B 28 4C EB 87 52 58 FD E3 EB 8C 54 9C 8E 0E F7";
//http请求
void uploadSn(String sn)