zoukankan      html  css  js  c++  java
  • 图灵机器人

    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); 
    	}
    }
    

      

  • 相关阅读:
    CF754A
    快速幂模板
    循环-21. 求交错序列前N项和(15)
    循环-20. 猜数字游戏(15)
    循环-19. 币值转换
    循环-18. 龟兔赛跑(20)
    循环-17. 简单计算器(20)
    循环-11. 水仙花数(20)
    IO 分支 循环
    check list
  • 原文地址:https://www.cnblogs.com/Sunnor/p/4671268.html
Copyright © 2011-2022 走看看