You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase云函数报错-1007:HTTP重定向过多问题排查求助

Firebase云函数调用报错:too many HTTP redirects(错误码-1007)

问题现象

  • 调用极简的https.onCall云函数时触发FirebaseFunctionsException,错误码-1007(too many HTTP redirects)
  • 虚拟设备、真机均会出现该问题,卸载应用无法解决
  • 云函数控制台无正常日志输出,仅能看到两条错误日志:

    "Request has invalid method. GET"
    "Error: Invalid request, unable to process. at entryFromArgs..."

相关代码

云函数代码

exports.belleDiana = functions.region(CLOUD_REGION).https.onCall(async (data, context): Promise<String> => {
    console.log("belleDiana", data, context);
    console.log("context.auth", context.auth?.uid, context);
    return "belleDianaDone";
});

Flutter端调用代码

try {
  final result =
  await FirebaseFunctions.instance.httpsCallable('belleDiana').call();
  print("result: $result");
} on FirebaseFunctionsException catch (error) {
  print(error);
  print(error.code);
  print(error.details);
  print(error.message);
}

问题分析

  1. 重定向触发原因:https.onCall类型的云函数仅接受POST请求,但日志显示收到的是GET请求,请求方式不匹配会导致云函数服务端返回重定向响应,客户端反复重定向超出次数限制后触发该错误。
  2. 区域配置关联:如果修改云函数区域后,Flutter客户端未同步配置对应区域,请求会发送到错误的端点,服务端会返回重定向到正确区域的地址,多次重定向后触发报错。

解决步骤

  • 同步客户端区域配置:在Flutter中初始化FirebaseFunctions时指定与云函数一致的区域,避免请求发送到错误端点:
    FirebaseFunctions functions = FirebaseFunctions.instanceFor(region: "你的CLOUD_REGION值");
    final result = await functions.httpsCallable('belleDiana').call();
    
  • 重新部署云函数:确认部署日志中显示的区域与代码中CLOUD_REGION一致,确保函数部署成功、端点有效。
  • 清除本地缓存:Android端可清除应用存储,iOS端删除应用后重启设备,避免旧的端点缓存导致请求异常。
  • 验证调用方式:确保使用httpsCallable方法调用,该方法会自动处理https.onCall要求的POST请求格式,不要手动发送GET请求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 11:02:10