Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- import java.io.*;
- import java.util.Scanner;
- public class SiteLoader {
- public static String load(String x) throws IOException{
- URL url = new URL(x);
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- System.out.println(connection.getResponseCode() + " " + connection.getResponseMessage());
- InputStream in = connection.getInputStream();
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String curline;
- StringBuilder content = new StringBuilder();
- while( (curline = br.readLine()) != null ){
- content.append(curline + '\n');
- }
- br.close();
- connection.disconnect();
- return content.toString();
- }
- public static void main(String[] args){
- System.out.println("netspeak request:");
- Scanner input = new Scanner(System.in);
- String answer = input.nextLine().toLowerCase();
- try{
- String request = URLEncoder.encode(answer, "UTF-8");
- String content = SiteLoader.load("http://api.netspeak.org/netspeak3/search?query="+request);
- System.out.println(content);
- }catch(MalformedURLException e) {
- System.out.println("MalformedURLException:" + e.getMessage());
- }catch(IOException e) {
- System.out.println("IOException:" + e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement