- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 Java 中的 wit.ai 开发虚拟助手,但我无法发出 HTTP 请求。我不是 Java 中 HTTP 请求的专家,我一直收到错误 400。
这是我的代码:
public class CommandHandler {
public static String getCommand(String command) throws Exception {
String url = "https://api.wit.ai/message";
String key = "TOKEN HERE";
String param1 = "20141022";
String param2 = command;
String charset = "UTF-8";
String query = String.format("v=%s&q=%s",
URLEncoder.encode(param1, charset),
URLEncoder.encode(param2, charset));
URLConnection connection = new URL(url + "?" + query).openConnection();
connection.setRequestProperty ("Authorization Bearer", key);
connection.setRequestProperty("Accept-Charset", charset);
InputStream response = connection.getInputStream();
return response.toString();
}
这是例子wit.ai给出:
$ curl \
-H 'Authorization: Bearer $TOKEN' \
'https://api.wit.ai/message?v=20141022&q=hello'
希望有人能帮帮我
最佳答案
下面是快速检查你的rest api的简单代码
try {
URL url = new URL("https://api.wit.ai/message?v=20170218&q=Hello");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("Authorization", "Bearer addkeyhere");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
关于java - wit.ai - 如何用 Java 发送请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35358232/
我知道 Wit.ai 引擎可以通过手动验证案例来训练,但是有没有办法用一组定义的输入和输出来训练它? 最佳答案 您可能可以查看其中一个应用程序的导出格式并对其进行调整以导入新应用程序。 https:/
来自 wit.ai 团队的一些人请回答这个 我们计划将 wit.ai 用于商业目的。有使用政策吗?请提供一些注意事项指南。此外,这项服务将来是否也是免费的,还是您计划推出企业版? 主要是 API 命中
我正在尝试训练我的 Wit.ai 机器人以识别某人的名字。我不太确定我是否完全理解 NLP 的工作原理,所以我会给你一个例子。 我定义了很多表达,比如“我的名字是XXXX”、“大家都叫我XXXX” 在
我似乎无法让这个请求生效: https://wit.ai/docs/http/20160526#delete--entities-:entity-id-values-link 我已经设置了一个值为“C
我正在尝试在 wit.ai 中编写示例应用程序。我使用在 https://wit.ai/docs/quickstart 中显示的 node.js 客户端跟随快速启动应用程序。 .那里显示的示例只有一个
我目前正在与 Wit.ai 合作 webpage in CodePen.io .我想知道是否可以使用 HTTP API 检索 Wit.ai 机器人的文本响应(“Bot says”)。 例如:如果用户要
我使用以下方法 ( https://wit.ai/docs/http/20160526#post--entities-:entity-id-values-link ) 将关键字添加到用户定义的实体,并
Wit AI project 在他们的 Converse 功能中添加了一个名为 Story 的新概念。有没有办法通过 HTTP API 管理(创建/编辑/验证)这些 Wit AI 故事? 最佳答案 W
例如,我正在尝试制作一款可以随机向您推荐电影的应用。您应该能够通过按下按钮与应用程序对话。然后该应用程序会将您的语音发送到后端( Node 应用程序),然后后端将运行逻辑,然后将随机电影标题发回给您。
我正在尝试开发一个天气机器人,但遇到了一些问题。 我用故事和理解标签来训练系统。机智的行为对我来说似乎是不可预测的 - 它结合了故事(我猜它应该这样做),所以看起来随机交谈。 意图值也不一致,即使使用
一、什么是 Protocol Witness Table? 我们都知道 C 函数调用是静态派发,简单来说可以理解为是用汇编命令 call $address 来实现,这种方式效率最高,但是灵活性不够。
我有以下问题。 我在对话中有几个要点,我必须捕获“自由”文本。 例如:你对 xyz 有什么看法?你为什么想要 xyz ?...它们是开放的问题,用户可以回答他们想要的任何问题。 如何启用此功能?因为我
针对自身实体有三种搜索策略:trait、free-text 和 keywords,如 explained in the documentation 。我无法理解的是这些选项允许的组合。我可以选择: 特
我正在尝试使用 Wit.ai 语音识别。我已经成功地能够将波形文件发送到网站以转换为文本,但现在我正尝试分 block 发送它以减少延迟,但每当我尝试这样做时,它都会给我错误 "content-typ
见证服务器有什么用?为什么要使用它? 最佳答案 见证人是将第三次投票纳入其中以创建法定人数的人。校长和镜像各有一票,因此可以 1:1 平局,无法做出决定。有了见证人,就可以建立 2:1 或 1:2 的
更新:下面提到的stackoverflow给出了另一种解决方案,即导入json并用正确格式的数据替换文本。我现在试图看看如何适应给定的格式,它看起来像这样: { "text" : "use
关于如何将日期/时间引用传递给基本的 Vanilla 小鸭服务器的任何指示? 我正在使用小鸭来解析文本。在查找时间表达式时,我需要传入一个引用日期/时间。 引用日期/时间为我提供了“昨天”和“今天”等
我试图以无形的方式理解单例类型,并面临对单例类型编译时类型的误解。下面是一个例子: val x: Witness.`120`.T = 120.narrow 它工作正常,但这种结构看起来很不寻常。什么是
我正在使用 wit ai 和 facebook messenger 开发一个应用程序,一切都按预期工作,但我被困在一个总是返回错误角色的表达式上。 我已经为该意图添加了类似的表达,但是当我测试同一个句
我在 GitHub 上修改 wit.ai 的 messenger.js 时遇到一些问题。我添加了一些 API 调用来获取实时天气,但我无法将结果输入机器人的回复(context.forecast)。
我是一名优秀的程序员,十分优秀!