Firebase 函数从 get 请求返回 400

标签 firebase google-cloud-functions firebase-admin

我的本地函数运行良好

firebase serve --only functions

但是一旦将它部署到云中,我就无法使用 postman 向它发出相同的 get 请求。我在 stackdriver 上收到以下错误:
Unexpected token u in JSON at position 0 at JSON.parse ,我的请求返回以下内容:400. That’s an error.Your client has issued a malformed or illegal request. That’s all we know.
我在本地和 firebase 中发送的数据是 GET请求类型 application/json有一个 body :{ "data": { "Celebrity_A": "Brad Pitt", "Celebrity_B": "Angelina Jolie" } }
与本地相比,firebase 功能期望远程有什么要求?

下面是我的函数的开始:
// Main index.ts
exports.funct = functions.https.onRequest(functexp)

// functexp file
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as _request from 'request';
const serviceAccount = require('./credentials.json');
admin.initializeApp({
    credential: admin.credential.cert(serviceAccount)
});
const db = admin.firestore();

export function functexp(request, response) {
    console.log(`request`);
    console.log(request);
    let celebName_A = null;
    let celebName_B = null;
    if(request !== undefined){
        celebName_A = request.body.data['Celebrity_A'];
        celebName_B = request.body.data['Celebrity_B'];
        console.log(`celebA is ${celebName_A}`)
    } etc...
}

最佳答案

尝试将您的请求发送为 POST方法,你看不到GET经常用 body 请求,这就是为什么 POST更安全,它从不缓存,最重要的是没有大小限制,也许这就是导致您的 GET 的原因。请求不起作用。

希望能帮助到你。

关于Firebase 函数从 get 请求返回 400,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53729414/

相关文章:

javascript - 由于某种原因在 native react 中渲染后发生 ComponentWillMount

javascript - 引用错误 : noticication_id is not defined in firebase notification

python-3.x - 使用 Cloud Functions 将文件从 Google Cloud Storage 传输到 Windows VM 实例

firebase - 如何从 Firebase 获取所有设备 token ?

java - 无法从 java admin sdk 将数据添加到 firebase 实时数据库

javascript - Firebase 后端 Node.js Nodmailer 'ENOTFOUND'

node.js - 在 Callable Firebase Functions 中获取请求 URL

ios - Flutter IOS 产品口味未运行

node.js - 我可以在 Cloud Functions Http 触发器中的 Firebase 身份验证上创建用户吗?

node.js - Firebase Functions 模拟器错误 : Cannot find module '../service-account.json'