各位前輩好,小弟最近在做專題,用到ESP32發送http post,在操作的途中,關於ESP32發送http post的程式碼中,有些代碼,不太了解是甚麼意思,爬文也沒有找到相關解釋,如果可以還請各位前輩幫忙解答一下,謝謝。
以下先附上完整程式碼
1 if(WiFi.status()== WL_CONNECTED){   //Check WiFi connection status
2  
3    HTTPClient http;   
4  
5    http.begin("http://7554-42-72-125-57.ngrok.io/callback?message=" +       6 uuid);  //Specify destination for HTTP request
7    http.addHeader("Content-Type", "text/plain");             //Specify      8 content-type header   
9  
10    int httpResponseCode = http.POST("POSTING from ESP32");   //Send the    11 actual POST request
12  
13    if(httpResponseCode>0){
14      Serial.println(httpResponseCode);   //Print return code  
15    }else{
16      Serial.print("Error on sending POST: ");
17      Serial.println(httpResponseCode);
18    }
19  
20    http.end();  //Free resources
21  }else{
22  
23    Serial.println("Error in WiFi connection");   
24  
25      }
其中第10~20行,不是很理解,如果可以再麻煩前輩幫忙了。
謝謝各位前輩
直接打 ngrok 就失敗
Google 最大的收獲是這個網站
可以模擬 ESP32/HTTP client
還包 source code
我改成你的 ngrok 的 URL,隨便塞個 UUID
結果得到 -3 的 response code
看起來原因應該是出在 ngrok 端了...