c# - 电报机器人 : Wrong response from the webhook: 404 Bad Request

标签 c# heroku telegram-bot

我在 Heroku 上部署了电报机器人。 Bot过去工作得很好,但在某些时候它只是在接收命令时停止发送消息。这是 getWebHookInfo 的答案:

{"ok":true,"result":{"url":"https://telegram-rainbow-bot.herokuapp.com:443/api/message/update","has_custom_certificate":false,"pending_update_count":1,"last_error_date":1613676609,"last_error_message":"Wrong response from the webhook: 404 Not Found","max_connections":40,"ip_address":"54.171.62.111"}}

我不知道发生了什么。机器人像往常一样工作,但突然发生了这种情况。 Bot 使用端口 443 进行 https 请求。有时日志也会显示“无法确定重定向的 https 端口”。

最佳答案

我设法解决了这个问题(尽管我不确定这是否是正确的方法)。一开始,我遇到了错误代码 404 的问题。这个问题通过在 Startup.cs 的配置方法中添加 UseRouting() 来修复。然后我遇到了错误代码 400 的问题。我通过安装 Microsoft.AspNetCore.Mvc.NewtonsoftJson nuget 包修复了这个问题,然后在 Startup.cs 的 ConfigureServices 方法中添加了 AddControllers().AddNewtonsoftJson() 。可能我的代码没有正确处理来自 Telegram 的 JSON。希望对大家有帮助。

关于c# - 电报机器人 : Wrong response from the webhook: 404 Bad Request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66264439/

相关文章:

c# - 如何在 .Net 5 的 API 响应中添加错误或响应代码?

python - 如何使用 telethon 向我的 channel 发送消息

telegram - 如何在我的 Telegram Bot 中读取/接收 Telegram channel 消息?

java - 如何更改 Telegram Bot 消息中的图片?

C#调用接口(interface)方法非虚实现

c# - 如何对涉及 SynchronizationContext 的代码进行单元测试?

ruby-on-rails - 在 Heroku 的 paper_trail 中自动设置谁负责控制台的更改

node.js - Heroku 的替代品

c# - 自动更新IoT核心应用

django - '网络 :' is not recognised as an internal or external command