Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.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
curl命令返回html而不是node.js_Node.js_Json_Facebook_Curl_Heroku - Fatal编程技术网

curl命令返回html而不是node.js

curl命令返回html而不是node.js,node.js,json,facebook,curl,heroku,Node.js,Json,Facebook,Curl,Heroku,我正在尝试通过heroku创建和托管一个webhook,使用以下Facebook messenger教程:。 因此,我目前正在测试对本地主机的cURL请求。本请求: curl -H "Content-Type: application/json" -X POST "localhost:3000/" -d "{""object"": ""page"", ""entry"": [{""messaging"": [{""message"": ""TEST_MESSAGE""}]}]}" 应该在cmd

我正在尝试通过heroku创建和托管一个webhook,使用以下Facebook messenger教程:。 因此,我目前正在测试对本地主机的cURL请求。本请求:

curl -H "Content-Type: application/json" -X POST "localhost:3000/" -d "{""object"": ""page"", ""entry"": [{""messaging"": [{""message"": ""TEST_MESSAGE""}]}]}"
应该在cmd中返回接收到的事件,并在第二个cmd窗口中测试_消息,在该窗口中我正在执行我的应用程序。 为了执行应用程序,我使用了$node index.js,我收到了“webhook侦听”,这意味着我执行它的方式没有错误

我的文件index.js如下所示:

'use strict';

// Imports dependencies and set up http server
const
  express = require('express'),
  bodyParser = require('body-parser'),
  app = express().use(bodyParser.json()); // creates express http server

// Sets server port and logs message on success
app.listen(process.env.PORT || 3000, () => console.log('webhook is listening'));
// Creates the endpoint for our webhook 
app.post('/webhook', (req, res) => {  

  let body = req.body;

  // Checks this is an event from a page subscription
  if (body.object === 'page') {

    // Iterates over each entry - there may be multiple if batched
    body.entry.forEach(function(entry) {

      // Gets the message. entry.messaging is an array, but 
      // will only ever contain one message, so we get index 0
      let webhook_event = entry.messaging[0];
      console.log(webhook_event);
    });

    // Returns a '200 OK' response to all requests
    res.status(200).send('EVENT_RECEIVED');
  } else {
    // Returns a '404 Not Found' if event is not from a page subscription
    res.sendStatus(404);
  }

});
// Adds support for GET requests to our webhook
app.get('/webhook', (req, res) => {

  // Your verify token. Should be a random string.
  let VERIFY_TOKEN = "somepassword"

  // Parse the query params
  let mode = req.query['hub.mode'];
  let token = req.query['hub.verify_token'];
  let challenge = req.query['hub.challenge'];

  // Checks if a token and mode is in the query string of the request
  if (mode && token) {

    // Checks the mode and token sent is correct
    if (mode === 'subscribe' && token === VERIFY_TOKEN) {

      // Responds with the challenge token from the request
      console.log('WEBHOOK_VERIFIED');
      res.status(200).send(challenge);

    } else {
      // Responds with '403 Forbidden' if verify tokens do not match
      res.sendStatus(403);      
    }
  }
});
这是我得到的回应(一些html代码):


错误
无法发布/
我没有收到错误,只是“错误”返回。

有人知道如何解决这个问题并接收“已接收事件”和“测试消息”吗

注意:我已经看到了下面的文章,并且我确实更改了与相关教程中的一些代码,但是我仍然无法解决这个问题


我也读了,但它也没有解决我的问题。

您忘记了在curl命令中使用的url中包含/webhook


您忘记了在curl命令中使用的url中包含/webhook


是的,就是这样。为我工作。多么愚蠢的错误!是的,就是这样。为我工作。多么愚蠢的错误!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /</pre>
</body>
</html>
curl -H "Content-Type: application/json" -X POST "localhost:3000/webhook"