botframework - 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"
}
}
我想知道我们在这篇文章中缺少什么。
解决方案
2017.3.X 版本中的 POST 实现发生了一些变化,他们开始使用 Transfer-Encoding: chunked Header,这导致这些数字出现在我们的 JSON 周围。为了防止这种行为,我们需要做的就是在创建之后添加这行代码UnityWebRequest: webRequest.chunkedTransfer = false;
推荐阅读
- sql - 获取过去 30 天内的行,不包括今天
- regex - 正则表达式来识别无括号的 if 语句
- python - 当我将它写入excel时,pandas pivot_table() 在我的数据框中放置了一个不需要的列,为什么?
- python - Pandas 子图布局在这种情况下不起作用
- r - 如何将我的列(字符)转换为 POSIXct 以创建时间序列?
- http-headers - iframe 重定向时如何传递授权标头?
- java - 会话值在 Safari 浏览器中不可用
- json - How to read an object from an script of index.html in angular
- php - Php - 如何扫描大图像文件夹并删除未使用的图像
- pycharm - Pycharm 社区版无法在 Windows 7 32 位中打开