HTTP 正文中的活动无效或缺失 - 作为对的响应的错误
Invalid or missing activities in HTTP body - error as a response to
我们正在尝试使用 https://github.com/tompaana/bot-direct-line-for-unity 将 Unity 应用程序与 Chatbot 连接起来。开始与 bot 的新对话工作正常,但是当我尝试向它发送消息时,我没有收到回复,而是在下面附加了错误。 Bot 与 web/skype 一起正常工作,我们唯一的问题是我们的统一实施。
我想知道我们在 POST 中缺少什么才能收到机器人的正确响应。
由于 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"
}
}
我想知道我们在这个 POST 中遗漏了什么。
POST 2017 年实施。3.X 版本发生了一些变化,他们开始使用 Transfer-Encoding: chunked Header,这导致这些数字出现在周围我们的JSON。为了防止这种行为,我们需要做的就是在创建 UnityWebRequest: webRequest.chunkedTransfer = false;
之后添加这行代码
在older version API中,UnityWebRequest.chunkedTransfer属性的默认值为true,如你提到,为了防止它,我们可以明确设置:
UnityWebRequest.chunkedTransfer = false;
此外,在the latest version中,UnityWebRequest.chunkedTransfer属性的默认值是false .因此,如果升级并使用最新版本,可能不会导致此问题。
我们正在尝试使用 https://github.com/tompaana/bot-direct-line-for-unity 将 Unity 应用程序与 Chatbot 连接起来。开始与 bot 的新对话工作正常,但是当我尝试向它发送消息时,我没有收到回复,而是在下面附加了错误。 Bot 与 web/skype 一起正常工作,我们唯一的问题是我们的统一实施。
我想知道我们在 POST 中缺少什么才能收到机器人的正确响应。
由于 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"
}
}
我想知道我们在这个 POST 中遗漏了什么。
POST 2017 年实施。3.X 版本发生了一些变化,他们开始使用 Transfer-Encoding: chunked Header,这导致这些数字出现在周围我们的JSON。为了防止这种行为,我们需要做的就是在创建 UnityWebRequest: webRequest.chunkedTransfer = false;
在older version API中,UnityWebRequest.chunkedTransfer属性的默认值为true,如你提到,为了防止它,我们可以明确设置:
UnityWebRequest.chunkedTransfer = false;
此外,在the latest version中,UnityWebRequest.chunkedTransfer属性的默认值是false .因此,如果升级并使用最新版本,可能不会导致此问题。