【问题标题】:404 Not found on ngrok404 在 ngrok 上找不到
【发布时间】:2019-02-05 22:02:56
【问题描述】:

我在使用 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);  

}

【问题讨论】:

  • 这是 ngrok 的响应:{ "status_code": 404, "msg": "Not Found", "details": { "path": "/api/data" } }跨度>
  • 你用什么命令来启动 ngrok?

标签: http-status-code-404 ngrok


【解决方案1】:

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

地址中http声明的双重化可能导致404。

【讨论】:

    猜你喜欢
    • 2020-12-05
    • 2018-12-26
    • 1970-01-01
    • 1970-01-01
    • 2020-01-30
    • 2021-09-26
    • 2014-06-18
    • 1970-01-01
    • 2021-03-14
    相关资源
    最近更新 更多