Abstract: This class HttpUtil supports simple HTTP communication top of a silvertunnel-ng.org Netlib NetLayer.
The class org.silvertunnel_ng.netlib.util.HttpUtil contains different methods to execute a HTTP GET or POST request. All of these methods return a byte array as result which represents the HTTP response body. HttpUtil does not support reading or writing any HTTP header information, i.e. it is really a very simple way of communication.
Hint: HttpUtil only supports client-side HTTP.
It follows an example:
select the NetLayer implementation that should be used:
// classic: TcpipNetLayer with NetLayerIDs.TCPIP (--> HTTP over plain TCP/IP);
// anonymous: TorNetLayer with NetLayerIDs.TOR (--> HTTP over TCP/IP over Tor network):
NetLayer lowerNetLayer = NetFactory.getInstance().getNetLayerById(NetLayerIDs.TOR);
only if anonymous communication over Tor is selected: it makes sense to wait until the Tor startup is finished - optional:
// wait until TOR is ready (optional):
lowerNetLayer.waitUntilReady();
send HTTP GET request to URL http://httptest.silvertunnel.org:80/httptest/bigtest.jsp?id=example and receive the response:
// prepare parameters
TcpipNetAddress httpServerNetAddress = new TcpipNetAddress("httptest.silvertunnel-ng.org", 80);
String pathOnHttpServer = "/httptest/bigtest.jsp?id=example";
long timeoutInMs = 5000;// do the request and wait for the response byte[] responseBody = HttpUtil.get(lowerNetLayer, httpServerNetAddress, pathOnHttpServer, timeoutInMs); // print out the response System.out.println(new String(responseBody));
Top: [Netlib], Next: [Netlib HTTP Client for Apache API]
Wiki: Netlib HTTP Client for Apache API
Wiki: Netlib HTTP
Wiki: Netlib NetLayer
Wiki: Netlib