【问题标题】:Firestore HTTP Insomnia query : Stream error in the HTTP/2 framing layerFirestore HTTP Insomnia 查询:HTTP/2 框架层中的流错误
【发布时间】:2020-06-29 09:03:01
【问题描述】:

我正在尝试通过 Insomnia API 使用 HTTP 查询来查询我的 Firestore 数据库:

https://firestore.googleapis.com/v1/projects/typebot/databases/(default)/documents/users

用这个身体:

{
  "structuredQuery": {
    "from": [
        {
            "collectionId": "users"
        }
    ],
    "where": {
        "fieldFilter": {
            "field": {
                "fieldPath": "email"
            },
            "op": "EQUAL",
            "value": {
                "stringValue": "email@test.com"
            }
        }
    }
  }
}

我收到以下错误:

HTTP 查询:HTTP/2 成帧层中的流错误

知道有什么问题吗?

【问题讨论】:

  • 所以只有这个查询,没有其他人有这个问题?
  • 我忘记提供我正在查询的端点。我编辑了这个问题。如果我查询例如https://firestore.googleapis.com/v1/projects/typebot/databases/(default)/documents/users/<DOC_ID> => 它可以工作
  • 每个结构化查询都失败
  • 请编辑问题以显示您用于提出请求的代码。该错误听起来像是 HTTP 客户端的问题,而不是 Firestore 的问题。我们应该能够使用您在此处提供的内容重现该问题。
  • 我正在使用失眠症

标签: firebase google-cloud-firestore insomnia


【解决方案1】:

我在执行GET 请求时遇到了类似问题:

GET https://us-central1-my-project-id.cloudfunctions.net/getUsers HTTP/1.1
content-type: application/json
{
        "minAge": "18"
}

针对由此 Firestore HTTP 云函数定义的端点:

exports.getUsers = functions.https.onRequest(async (req, res) => {
    // find matching users by age limit.
    const ageLimit = req.body.age;
    ... 
  
});

事实证明,基于this other SO post,带有GET 的请求正文没有任何意义,因为HTTP 规范建议“在处理请求时应该忽略消息正文”(大概,由服务器,并且 Firestore 服务器实现此行为)。奇怪的是,我没有发现使用 Functions 模拟器在本地运行完全相同的函数的这个问题,因此本地服务器很可能忽略了这个建议。

为了解决这个问题,我更改了我的函数来解析查询参数而不是请求正文:

exports.getUsers = functions.https.onRequest(async (req, res) => {
    // find matching users by age limit.
    const ageLimit = req.query.age; // extract the age as a query param
    ... 
  
});

和请求:

GET https://us-central1-my-project-id.cloudfunctions.net/getUsers?age=18

【讨论】:

    【解决方案2】:

    可以尝试将“GET”更改为“POST”

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2021-07-15
    • 2023-01-07
    • 1970-01-01
    • 1970-01-01
    • 2016-06-01
    • 1970-01-01
    • 2022-10-04
    • 2016-09-15
    • 1970-01-01
    相关资源
    最近更新 更多