000
06.09.2006, 14:00 Uhr
J-jayz-Z
Perl Crack ala Carte (Operator)
|
Da es anscheinend ein paar Leute gibt, die sich weigern eine Java FAQ einzurichten, poste ich es mal hier Kleines Snippet, wie man eine HTML Datei runterladen kann mit Java. Hab ich ewig gesucht und ist find ich schlecht dokumentiert .... Deshalb der Code hier:
C++: |
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL;
import sun.net.www.protocol.http.HttpURLConnection;
class HtmlWork { private String content = null; private URL url = null; private HttpURLConnection connection = null; private InputStream stream = null; private Reader reader = null; private BufferedReader bufReader = null; HtmlWork(String url) throws IOException { this.url = new URL(url); this.connection = (HttpURLConnection)this.url.openConnection(); this.stream = this.connection.getInputStream(); this.reader = new InputStreamReader(this.stream, "ISO8859_1"); this.bufReader = new BufferedReader(this.reader); String line = new String(); StringBuffer tmpContent = new StringBuffer(); while((line = this.bufReader.readLine()) != null) { line = line.trim(); tmpContent.append(line.trim()+"\n"); } this.bufReader.close(); this.content = tmpContent.toString(); } public String getContent() { return this.content; } public static void main(String[] args) { try { HtmlWork work = new HtmlWork("http://www.fun-soft.de/index.php"); System.out.println(work.getContent()); } catch (IOException e) { e.printStackTrace(); } } }
|
-- perl -Mstrict -Mwarnings -e 'package blub; sub new { bless {} } sub bar {my $self=shift; $self->{bla}="66756e2d736f66742e6465"; return $self->{bla};} my $foo=blub->new();print "Hallo ";print pack("H*",$foo->bar()); print "\n"' |