問:您好,我之前還沒配置SSL時,用nodemcu 傳感器可以對http進行請求,更改數據庫,并回傳,但配置了SSL后就出錯了,錯誤是我在硬件上檢測到的,“The plain HTTP was sent to HTTPS port” 目前是無法寫數據和回傳的,我網上查了一篇文章https://blog.csdn.net/iteye_5799/article/details/ 應該在服務器上可以配置。也就是我還能用HTTP原來的方式進行調用和回傳。具體的程序我附在下方,麻煩看看怎么解決。我微信小程序又要用到SSL,所以不能停用SSL,謝謝
#include <ESP8266WiFi.h>#include <dht11.h> dht11 DHT; const char* ssid = \”\”;//改為你設置的網絡 char* = \”\”;//改為你設置的網絡密碼 const char* host = \”www.sjrjw.com\”;//改為你設置的網站域名#define LED_BUILTIN D7 //LED連接在8266的GPIO0上 代碼燒錄進8266,燒寫完成后把LED的正極接GPIO0,LED的負極接地#define DHT_BUILTIN D4 //DHT連接在8266的GPIO2上 代碼燒錄進8266,燒寫完成后把DHT11的正極接GPIO2 做為輸入int switch1=1;void setup() { Serial.begin; delay(10); pinMode(LED_BUILTIN, OUTPUT); pinMode(DHT_BUILTIN, INPUT); Serial.println(); Serial.println(); Serial.print(\” to \”); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print(\”.\”); } Serial.println(\”\”); Serial.println(\”WiFi \”); Serial.println(\”IP address: \”); Serial.println(WiFi.localIP());} int value = 0; void loop() { delay(1000);//可以用這一個來調整響應和心跳速度 value; Serial.print(\” to \”); Serial.println(host); if(switch1 == \’0\’){ digitalWrite(LED_BUILTIN, LOW); }else if(switch1 == \’1\’){ digitalWrite(LED_BUILTIN, HIGH); }int chk; //chk用于存儲DHT11傳感器的數據Serial.print(\”DHT11, \\t\”); //讀取DHT11傳感器的數據 chk = DHT.read(DHT_BUILTIN);
client; const int =443;//開啟SSL后端口改為443,http端口為80 if (!client.connect(host, httpsPort)) { Serial.println(\” failed\”); return; } // We now a URI for the url = \”/updown.php\”; //表示你傳到網站上的傳輸文件 url = \”?token=\”; url = \”\”;//要加上這一個token和的要一致 url = \”&temp=\”; url = DHT.temperature; url = \”&humidity=\”; url = DHT.humidity; Serial.print(\” URL: \”); Serial.println(url); // This will send the to the client.print(String(\”GET \”) url \” HTTP/1.1\\r\\n\” \”Host: \” host \”\\r\\n\” \”User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36\” \”\\r\\n\” \”Connection: close\\r\\n\\r\\n\”); long = millis(); while (client.available() == 0) { if (millis() – > 5000) { Serial.println(\”>>> Timeout !\”); client.stop(); return; } } // Read all the lines of the reply from and print them to while(client.available()){ char c = client.read(); Serial.println( c); if (c == \'{\’){ = client.read(); } } Serial.println( switch1); Serial.println(\” connection\”);}
,主機配置完SSL出錯
答:您好,由于 https 相對于 http 多了一個客戶端和服務端協商證書的過程, 所以需要確保您的 client 對象能夠正常的發送 https 握手的過程, 可以測試訪問 https://www.baidu.com, 解決方法: 您可以嘗試使用 庫試試,非常感謝您長期對我司的支持!
三五互聯(35.com)是經工信部、ICANN、CNNIC認證審批,持有ISP、云牌照、IDC、CDN、頂級域名注冊商等全業務資質的正規老牌服務商,自成立至今20余年專注于域名注冊、虛擬主機、云服務器、企業郵箱、企業建站等互聯網基礎服務!
截止目前,已經為超過2000萬個域名提供了注冊、解析等服務,是中國五星級域名注冊注冊商!已為超過50萬個網站提供了高速穩定的云托管服務,獲評中國最受用戶喜歡云主機服務商。
三五互聯提供全方位7X24H專業售后支撐,域名注冊特價1元起,高速穩定云主機45元起,更多詳情請瀏覽三五互聯官網:http://www.shinetop.cn/