尝试使用curl将json发布到节点JS服务器但超时 编辑 PS:

我正在开发一个在nodejs服务器上托管的Facebook Messenger机器人,该机器人可以从自定义API访问数据。

我正在尝试使用curl将发送数据发送到我的nodejs服务器。 发生了什么事,就是我收到了数据,并且可以发送带有该数据的Messenger消息,但是在后台我的curl请求超时了。


这是我的卷曲要求

   $data = array(
        "textvalue" => $messageFB,"sender_id" => $questionCreator['bot_fb_sender_id'],'notify' => 1
    );

    $data_string = json_encode($data)

    $ch = curl_init('some url');
    curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"POST");
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HTTPHEADER,array(
        'Content-Type: application/json','Content-Length: ' . strlen($data_string))
    );
    curl_setopt($ch,CURLOPT_TIMEOUT,2);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1);

    $res  = curl_exec($ch);
    curl_close($ch);


这是我通过nodeJS收到它的方式

app.post('/notify',(req,res) => {

    if (req.body.notify > 0) {
        var user = {
          id: req.body.sender_id
        }
        console.log("value of id extern : " + user.id);
        var text = [];

        text[0] = {"text": req.body.textvalue.replace(/<[^>]*>?/gm,'')};

        call.Sendaction(user);
        call.SendApi(user,text);
    }
});


这是我得到的错误

at=error code=H12 desc="Request timeout" method=POST path="/notify" host=team-bot-4858.herokuapp.com request_id=818b120b-4305-4aa6-ba4d-80dff02f61b9 fwd="176.162.183.225" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=http

编辑

  • 我尝试通过设置来增加我的卷曲请求的超时时间 CURLOPT_CONNECTTIMEOUT to 0CURLOPT_TIMEOUT to 400,但仍然超时仍不会改变结果。
  • 在我的error_log文件中进行一些挖掘之后,我发现了超时的原因(我认为...),该错误在下面。
curl_exec(): supplied resource is not a valid cURL handle resource

PS:

  • 我是Web开发的新手,所以我选择的单词或 描述可能不太清楚

  • 我也提前为我的英语道歉(不是我的母语)。

photon0 回答:尝试使用curl将json发布到节点JS服务器但超时 编辑 PS:

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3066741.html

大家都在问