privatestaticboolean hasFtp() { try { returnnew java.net.URL("ftp://") != null;
} catch (java.net.MalformedURLException x) {
System.out.println("FTP not supported by this runtime."); returnfalse;
}
}
publicstaticvoid main(String[] args) throws Exception { if (hasFtp()) new ProxyTest();
}
public ProxyTest() throws Exception {
BufferedReader in = null;
String testURL = "ftp://anonymous:password@myhost.mydomain/index.html";
HttpProxyServer server = new HttpProxyServer(); try {
server.start(); int port = server.getPort();
InetAddress loopback = InetAddress.getLoopbackAddress();
Proxy ftpProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(loopback, port));
URL url = new URL(testURL);
InputStream ins = (url.openConnection(ftpProxy)).getInputStream();
in = new BufferedReader(new InputStreamReader(ins));
String line; do {
line = in.readLine();
} while (line != null);
in.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
server.terminate(); try { in.close(); } catch (IOException unused) {}
} /* *IftheURLsdon'tmatch,we'vegotabug!
*/ if (!testURL.equals(server.getURL())) { thrownew RuntimeException(server.getURL() + " != " + testURL);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.