404在ngrok上找不到 [英] 404 Not found on ngrok

查看:438
本文介绍了404在ngrok上找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a problem with ngrok and arduino, i send a message but when i open ngrok it says: 404 Not found

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

I think it could be problem with port, I use 4040 because ngrok open localhost:4040 but i don't know if it is true. The server-side app on java use port 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);  

}

推荐答案

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

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

The double-up of http declaration in the address is likely causing the 404.

这篇关于404在ngrok上找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆