图灵机器人
package com.xxx.work;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Scanner;
public class Turing {
/**
* 说明:图灵机器人库从网上就可以找到
*/
private static void testTuring(String str){
final String key = "e7a1447ed2182d57758ca845e5a0f36e";
String info = "";
try {
info = URLEncoder.encode(str, "utf-8");
String spec = "http://www.tuling123.com/openapi/api?key="+key+"&info="+info;
URL url = new URL(spec);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.connect();
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8"));
String line = "";
StringBuilder sb = new StringBuilder();
if((line=br.readLine())!=null){
sb.append(line);
}
br.close();
connection.disconnect();
System.out.println(sb);
} catch (IOException e) {
System.err.println("异常的信息:"+e.getMessage());
e.printStackTrace();
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
testTuring(str);
}
}