码迷,mamicode.com
首页 > 其他好文 > 详细

图灵机器人

时间:2015-07-23 19:47:54      阅读:171      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!