You need to enable JavaScript to run this app. Controllino MAXI对接Firebase Realtime Database REST API PUT请求报404问题
优惠活动
大模型
产品
解决方案
定价
更多

Controllino MAXI对接Firebase Realtime Database REST API PUT请求报404问题

开发板对接Firebase Realtime Database 请求异常问题

基础信息

  • 硬件平台:Controllino MAXI,本质为搭载以太网芯片的Arduino Mega 2560,参考产品介绍Controllino MAXI
  • 开发目标:通过Firebase Realtime Database提供的REST API,实现开发板向数据库传输数据的功能
  • 当前故障现象:所有类型的HTTP请求均无法正常生效,现阶段优先聚焦PUT请求的链路排查

正常验证链路

使用在线测试工具reqbin验证PUT请求可正常完成写入,对应原始请求报文:

PUT /.json HTTP/1.1
Host: *rtdb-name*.firebaseio.com
Content-Type: application/json
Content-Length: 26

{"message":"hello world!"}

请求返回的正常响应内容:

{
    "message": "hello world!"
}

对应响应头信息:

Server: nginx
Date: Wed, 03 Feb 2021 17:02:55 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 26
Connection: keep-alive
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Strict-Transport-Security: max-age=31556926; includeSubDomains; preload

请求可正常将数据写入Realtime Database根节点,写入效果参考截图:Firebase Realtime Database 数据写入成功界面

开发板端异常表现

在开发板上调用Arduino Ethernet库,编写逻辑完全一致的请求代码,核心片段如下:

char server[] = "rtdb-name.firebaseio.com"
if (client.connect(server,80)){
    String data = "{\"message\":\"hello world!\"}";
    Serial.println("connected");
    client.println("PUT /.json HTTP/1.1");
    client.println("Host: *rtdb-name*.firebaseio.com");
    client.println("User-Agent: Arduino/1.0");
    client.println("Cache-Control:  no-cache, no-store, must-revalidate");
    client.println("Pragma: no-cache");
    client.println("Expires: 0");
    client.println("Content-Type: application/json");
    client.println("Connection: close");
    client.print("Content-Length: ");
    client.println(data.length());
    client.println();
    client.println(data);

    while(client.connected()) {
      while (client.available()) {
        char c = client.read();
        Serial.print(c);
      }
    }
   client.stop();     
   Serial.println("disconnected");
}else{
    Serial.println("Failed to connect to server");
}

实际收到的返回为404错误,报文内容:

HTTP/1.1 404 Not Found
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Content-Length: 1566
Date: Wed, 03 Feb 2021 17:06:07 GMT
Connection: close

初步推测方向

目前暂未定位到问题根因,初步判断可能是Firebase Realtime Database站点采用HTTPS协议强制跳转,而基于Mega架构的开发板原生仅支持HTTP通信,需要对应的技术指导与解决方案。

内容的提问来源于stack exchange,提问作者SRR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.05 11:36:04