404在ngrok上找不到

时间:2019-02-05 22:02:57

标签: http-status-code-404 ngrok

我对ngrok和arduino有问题,我发送了一条消息,但是当我打开ngrok时,它说:404 not found

我认为端口可能有问题,我使用4040,因为ngrok打开localhost:4040,但是我不知道这是不是真的。 Java上的服务器端应用程序使用端口80

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>

/* wifi network name */
char* ssidName = "mywifi";
/* WPA2 PSK password */
char* pwd = "mypwd";
/* service IP address */ 
char* address = "http://cf3c013e.ngrok.io";

void setup() { 
  Serial.begin(115200);                                
  WiFi.begin(ssidName, pwd);
  Serial.print("Connecting...");
  while (WiFi.status() != WL_CONNECTED) {  
    delay(500);
    Serial.print(".");
  } 
  Serial.println("Connected: \n local IP: "+WiFi.localIP());
}

int sendData(String address, float value, String place){  
   HTTPClient http;    
   http.begin(address + "/api/data");      
   http.addHeader("Content-Type", "application/json");     
   String msg = 
    String("{ \"value\": ") + String(value) + 
    ", \"place\": \"" + place +"\" }";
   int retCode = http.POST(msg);   
   http.end();  

   String payload = http.getString();  
   Serial.println(payload);      
   return retCode;
}

void loop() { 
 if (WiFi.status()== WL_CONNECTED){   

   /* read sensor */
   float value = (float) analogRead(A0) / 1023.0;

   /* send data */
   Serial.print("sending "+String(value)+"...");    
   int code = sendData(address, value, "home");

   /* log result */
   if (code == 200){
     Serial.println("ok");   
   } else {
     Serial.println("error");
   }
 } else { 
   Serial.println("Error in WiFi connection");   
 }

 delay(5000);  

}

1 个答案:

答案 0 :(得分:0)

http://删除char* address = "http://cf3c013e.ngrok.io";

地址中的http声明加倍可能导致404。

相关问题