Platinum Partner

Java - GetHTMLpage

// Scarica dalla rete una pagina HTML


package HttpGetIMGs;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

/*
 * 
 * Fa una richiesta di connessione al web e scarica la pagina...
 */

public class RandomIMGs
{
	private BufferedReader br;
	private OutputStreamWriter osw;
	private String data;
	private String line;
	private URL url;
	private URLConnection conn;
		
	public RandomIMGs()
	{
		try
		{
			url = new URL("http://flickr.com/photos");
			conn = url.openConnection();
			conn.setDoOutput(true);
			
			osw = new OutputStreamWriter(conn.getOutputStream());
			
			data = URLEncoder.encode("start", "utf-8") + "=" + URLEncoder.encode("1", "utf-8");
			osw.write(data);
			osw.flush();
			
			br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			
			while((line = br.readLine()) != null)
			{
				System.out.println(line);
			}
			
			osw.close();
			br.close();
		}
		catch(MalformedURLException e)
		{
			e.printStackTrace();
		}
		catch(IOException e)
		{
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args)
	{
		new RandomIMGs();
	}
}
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}