我有一个云功能,它是使用来自客户端浏览器的提取POST请求触发的,但是对提取调用的响应并不包含来自云功能的响应文本(res.send(" sampletext&#34))
云功能:
const functions = require('firebase-functions');
const cors = require('cors')({ origin: true })
exports.unlock = functions.https.onRequest((req, res) => {
cors(req, res, () => {
res.send('bsdasda');
})
})
在客户端浏览器上获取POST请求
fetch("https://us-central1-closing-ratio-32360.cloudfunctions.net/unlock", {
method: "post",
mode: "cors"
}).then((response) => {
console.log(response)
});
这是客户端浏览器上的获取响应
Response {type: "cors", url: "https://us-central1-closing-ratio-32360.cloudfunctions.net/unlock", redirected: false, status: 200, ok: true, …}
body
:
(...)
bodyUsed
:
false
headers
:
Headers {}
ok
:
true
redirected
:
false
status
:
200
statusText
:
""
type
:
"cors"
url
:
"https://us-central1-closing-ratio-32360.cloudfunctions.net/unlock"
__proto__
:
Response
答案 0 :(得分:1)
检查出来:
fetch("https://us-central1-closing-ratio-32360.cloudfunctions.net/unlock", {
method: "post",
mode: "cors"
})
.then((response) => response.text())
.then((text) => {
console.log(text)
});