【问题标题】:Telegram bot sendMessage parse_mode generates HTTP/1.1 400 Bad RequestTelegram bot sendMessage parse_mode 生成 HTTP/1.1 400 错误请求
【发布时间】:2020-03-10 09:04:38
【问题描述】:

使用电报的HTTP API在PHP中发送消息如下:

$msg = "New Comment is **added** from:\n".$domain;
    file_get_contents('https://api.telegram.org/botTOKEN:CODE/sendMessage?chat_id=@MYCHANNEL&text='.$msg.'&parse_mode=markdown');

仅添加最后一个参数&parse_mode=markdown 会导致 400 错误请求。删除它,一切正常。

但是,从 $msg 字符串中删除 \n 可以正常工作。

现在,我不知道为什么新行 \n 会导致 400 bad request。另外,我不知道如何在消息正文中添加新行!

【问题讨论】:

    标签: php telegram telegram-bot


    【解决方案1】:

    urlencode()消息;

    $msg = urlencode("New Comment is **added** from:\n" . "mydomain");
    

    url在找到换行后结束,因此PHP无法发送请求,导致400。

    【讨论】:

      猜你喜欢
      • 2017-07-21
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 2014-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多