Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Firebase函数获取文本响应错误“;JSON中的意外标记H“;_Node.js_Firebase_Google Cloud Functions - Fatal编程技术网

Node.js Firebase函数获取文本响应错误“;JSON中的意外标记H“;

Node.js Firebase函数获取文本响应错误“;JSON中的意外标记H“;,node.js,firebase,google-cloud-functions,Node.js,Firebase,Google Cloud Functions,我试图找出这个错误: "error: SyntaxError: Unexpected token H in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (http://localhost:4200/vendor.js:8646:51) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke

我试图找出这个错误:

"error: SyntaxError: Unexpected token H in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (http://localhost:4200/vendor.js:8646:51) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:2743:31) at Object.onInvokeTask (http://localhost:4200/vendor.js:38114:33) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:2742:36) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:4200/polyfills.js:2510:47) at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (http://localhost:4200/polyfills.js:2818:34) at invokeTask (http://localhost:4200/polyfills.js:3862:14) at XMLHttpRequest.globalZoneAwareCallback (http://localhost:4200/polyfills.js:3888:17)
text: "Hello from Firebase!"
下面是我对函数的调用:

exports.helloWorld = functions.https.onRequest((req, res) => {
  cors(req, res, () => {
    res.send("Hello from Firebase!");
  });
});
public sendHttpRequestTest(){
    let url = `my_link_to_functions/helloWorld`;
    const req = new HttpRequest("GET",url);

    this.http.request(req).toPromise()
        .then( res => {
          console.log(res);
        })
        .catch( err => {
          console.log(err);
        })
  }

我通过将其作为JSON发送来修复它,如下所示:

res.send(JSON.stringify("Hello from Firebase!"));

为什么对
url
变量使用模板文本?