HTTP正文中的活动无效或缺失 - 作为响应的错误

时间:2018-05-15 11:47:03

标签: botframework direct-line-botframework

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

我想知道我们在POST中缺少什么才能从bot获得适当的响应。

由于Unity在某种程度上缺少来自浏览器开发者工具包的Network / XHR等功能,因此我们使用Fiddler来获取这些结果:

这里是POST发送到chatbot:

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"
  }
}

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

2 个答案:

答案 0 :(得分:2)

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

之后添加这行代码

答案 1 :(得分:1)

older version API中, UnityWebRequest.chunkedTransfer 属性的默认值 true ,正如您所提到的,为了防止它,我们可以明确设置:

UnityWebRequest.chunkedTransfer = false;

此外,在the latest version中, UnityWebRequest.chunkedTransfer 属性的默认值为 false 。因此,如果升级并使用最新版本,则可能不会导致此问题。

enter image description here