我当前正在尝试创建本地服务器,以便可以使用Dialogflow与我的Google home通信。现在,我从中接收到POST JSON请求,但是我尝试使用已制定的JSON响应来响应这些请求。有什么简单的方法可以做到这一点吗?这是我的主班。 Listener类仅将Char输入转换为完整的String。评分器类制定了一个我想发送回Dialogflow的响应。
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class Init {
public static void main(String args[]) throws IOException {
int port = 8087;
String sentence = "";
ServerSocket server = new ServerSocket(port);
System.out.println("Server starting on " + port + "...");
while(true) {
Socket client = server.accept();
sentence = Listener.listener(client);
sentence = sentence.toLowerCase();
Scorer.scorer(sentence);
System.out.println(sentence);
}
}
}