首页 > 解决方案 > HTTP 正文中的活动无效或缺失 - 作为对以下内容的响应的错误

问题描述

我们正在尝试使用https://github.com/tompaana/bot-direct-line-for-unity将 Unity 应用程序与 Chatbot 连接起来。与 bot 开始新的对话工作正常,但是当我尝试向它发送消息时,我最终没有得到响应,而是在下面附加了错误。Bot 在 web/skype 上正常工作,我们唯一的问题是我们的统一实现。

我想知道我们在 POST 中缺少什么以便从 bot 接收正确的响应。

由于 Unity 缺少浏览器开发工具包中的 Network/XHR 等功能,因此我们使用 Fiddler 来获得这些结果:

这是发送到聊天机器人的 POST:

POST https://directline.botframework.com/v3/directline/conversations/CRar7Qz6VaEmIeMR6UmUC/activities HTTP/1.1
Host: directline.botframework.com
User-Agent: UnityPlayer/2017.3.1f1 (UnityWebRequest/1.0, libcurl/7.51.0-DEV)
Accept: */*
Accept-Encoding: identity
Transfer-Encoding: chunked
Authorization: Bearer XXX.edited_out.XXX
Content-Type: application/json
X-Unity-Version: 2017.3.1f1

76
{ "type": "message", "channelId": "directline", "from": { "id": "default-user", "name": "User" }, "text": "message text" }
0

这是回应:

HTTP/1.1 400 Bad Request
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 116
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/10.0
Request-Context: appId=cid-v1:91e46abb-4ce5-4d98-9375-02378f649011
X-Powered-By: ASP.NET
Strict-Transport-Security: max-age=31536000
Date: Tue, 15 May 2018 10:21:11 GMT

{
  "error": {
    "code": "MissingProperty",
    "message": "Invalid or missing activities in HTTP body"
  }
}

我想知道我们在这篇文章中缺少什么。

标签: botframeworkdirect-line-botframework

解决方案


2017.3.X 版本中的 POST 实现发生了一些变化,他们开始使用 Transfer-Encoding: chunked Header,这导致这些数字出现在我们的 JSON 周围。为了防止这种行为,我们需要做的就是在创建之后添加这行代码UnityWebRequest: webRequest.chunkedTransfer = false;


推荐阅读