gpt4 book ai didi

botframework - 400 来自使用 Postman 的本地机器人的错误请求

转载 作者:行者123 更新时间:2023-12-04 04:18:54 26 4
gpt4 key购买 nike

我正在尝试使用 ngrok 提供的链接使用 postman 测试我的机器人,即 https://xxxxxx.ngrok.io/api/messages .但是收到如下所示的 400 错误请求

postman 400 bad request

我尝试在我的控件上设置一个断点,它确实命中了,但它没有继续执行 catch 语句。

breakpoint hitting

我知道我的机器人没有任何问题,因为它在使用模拟器时工作正常。

emulator api

我的计划是在不注册任何 Azure 服务的情况下将我的机器人实现到我的自定义聊天中。

附加信息:

我的请求正文是空的。我遵循了这个问题的答案 MS bot tested locally with postman即使我使用此链接 https://xxxxx.ngrok.io/v3/directline/conversations ,它返回 404 未找到,如下所示。但是当我使用模拟器打开我的机器人然后使用/v3/directline/conversations 执行链接时它工作正常。

directline api postman

最佳答案

正如您链接的问题中的答案所述:

A bot running on localhost should be testable via any HTTP client such as Postman as long as your forming the requests correctly which really only means you just need a payload that is a valid activity representation.

当您使用模拟器时,如果形成请求的主体并且它成功。如果您想使用 Postman 探索 API 的工作方式,则必须根据框架文档形成请求。

/v3/directline/conversations API documentation声明您需要在请求正文中提供有效的 TokenParameters 对象才能获得响应。

要使用主要的 REST API,您需要使用云提供商提供的基本 URL:

When a user sends a message to your bot, the incoming request contains an Activity object with a serviceUrl property that specifies the endpoint to which your bot should send its response. To access the Bot Connector service, use the serviceUrl value as the base URI for API requests.

在 Bot Framework REST 中阅读更多内容 API Reference文档。

最后,尝试回答您的总体问题,我们可以看看 NGROK 服务只是一种公开本地环境的方式这一事实。 NGROK 服务提供的链接旨在供 Bot Framework 云服务使用,如 this tutorial 中所述。 .当您通过 NGROK 设置转发时,您可以通过 Facebook、Skype 等与您的机器人聊天,并在本地运行的应用程序中接收请求。如果您想调用您的应用程序的端点,当它在本地运行时,使用 Postman,您可以简单地使用 localhost:PORT_NUMBER 和您的 Dot Net 应用程序服务的端口号它的 HTTP API。

如果您查看提供的 starter code sample您将在 #14 行看到 Controller 被注释为服务于 /api/messages URL 上的请求。使用配置文件中指定的 applicationUrl 发出 GET 或 POST 请求。由于您的应用可能没有身份验证,因此您不需要 Bearer token 。最后,请记住 POST request 用于携带 body (即使 body 是空的)!这可能会导致您的工作流程出现问题。尝试使用 GET 请求,因为它是一种更简单的工具。

关于botframework - 400 来自使用 Postman 的本地机器人的错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59924285/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com