首页 > 其他 > 详细

图灵机器人

时间:2015-07-23 19:45:29      阅读:168      评论:0      收藏:0      [点我收藏+]
package com.wyl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

public class APItest {
	public static void main(String[] args) throws IOException {
		String APIKEY = "开发者注册帐号,激活之后即可获得"; 
	    String INFO = URLEncoder.encode("讲个笑话", "utf-8"); 
	    String getURL = "http://www.tuling123.com/openapi/api?key=" + "e59219b3f450256c2a3da7157ae651f2" + "&info=" + INFO; 
	    URL getUrl = new URL(getURL); 
	    HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection(); 
	    connection.connect(); 

	    // 取得输入流,并使用Reader读取 
	    BufferedReader reader = new BufferedReader(new InputStreamReader( connection.getInputStream(), "utf-8")); 
	    StringBuffer sb = new StringBuffer(); 
	    String line = ""; 
	    while ((line = reader.readLine()) != null) { 
	        sb.append(line); 
	    } 
	    reader.close(); 
	    // 断开连接 
	    connection.disconnect(); 
	    
	    System.out.println(sb); 
	}
}

  

图灵机器人

原文:http://www.cnblogs.com/Sunnor/p/4671268.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!