使用的是最普通的java工程调用图灵机器人的API(文档链接),人工智障在线聊天。。。。
- 首先自行封装一个post方法(get大体相同)代码如下:
public class HttpPost {
/**
* 向指定 URL 发送POST方法的请求
*
* @param httpUrl
* 发送请求的 URL
* @param param
* 请求参数是json
* @return 所代表远程资源的响应结果
*/
public static String doPost(String httpUrl, String param) {
HttpURLConnection connection = null;
InputStream is = null;
OutputStream os = null;
BufferedReader br = null;
String result = null;
try {
URL url = new URL(httpUrl);
// 通过远程url连接对象打开连接
connection = (HttpURLConnection) url.openConnection();
// 设置连接请求方式
connection.setRequestMethod("POST");
// 设置连接主机服务器超时时间:15000毫秒
connection.setConnectTimeout(15000);
// 设置读取主机服务器返回数据超时时间:60000毫秒