Qualcosa del genere?
codice:
import java.net.*;
import java.io.*;
/**
*
* @author Andrea
*/
public class URLReader {
private URL url;
private BufferedReader br;
private StringBuffer sbuf;
public String toString() {
return sbuf.toString();
}
/** Creates a new instance of URLReader */
public URLReader(String url, String referer) throws Exception {
this.url = new URL(url);
this.sbuf = new StringBuffer();
HttpURLConnection httpURLConnection = (HttpURLConnection)this.url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
httpURLConnection.setUseCaches(false);
httpURLConnection.setRequestProperty("Referer", referer);
httpURLConnection.setRequestProperty("User-Agent", "Internet Explorer");
this.br = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
String line = "";
while ((line = this.br.readLine()) != null) {
sbuf.append(line+"\n");
}
}
public static void main (String[] args) {
try {
URLReader ur = new URLReader("http://www.microsoft.com", "http://www.google.com");
System.out.println(ur);
}
catch (Exception e) {
e.printStackTrace();
}
}
}