use of com.generallycloud.baseio.codec.http11.HttpClient in project baseio by generallycloud.
the class TestSimpleHttpClient2 method main.
public static void main(String[] args) throws IOException {
String host = "www.baidu.com";
host = "generallycloud.com";
host = "127.0.0.1";
int port = 443;
port = 8080;
HttpIOEventHandle eventHandleAdaptor = new HttpIOEventHandle();
ServerConfiguration c = new ServerConfiguration(host, port);
SocketChannelContext context = new NioSocketChannelContext(c);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setProtocolFactory(new ClientHTTPProtocolFactory());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
if (port == 443) {
context.setSslContext(SSLUtil.initClient(true));
}
SocketSession session = connector.connect();
HttpClient client = new HttpClient(session);
HttpFuture future = new ClientHttpFuture(context, "/");
HttpFuture res = client.request(future, 99990000);
System.out.println();
System.out.println(new String(res.getBodyContent()));
System.out.println();
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.codec.http11.HttpClient in project baseio by generallycloud.
the class TestSimpleHttpClient method main.
public static void main(String[] args) throws Exception {
HttpIOEventHandle eventHandleAdaptor = new HttpIOEventHandle();
// ServerConfiguration c = new ServerConfiguration("localhost",80);
ServerConfiguration c = new ServerConfiguration("generallycloud.com", 443);
SocketChannelContext context = new NioSocketChannelContext(c);
SocketChannelConnector connector = new SocketChannelConnector(context);
SslContext sslContext = SSLUtil.initClient(true);
context.setProtocolFactory(new ClientHTTPProtocolFactory());
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
context.setSslContext(sslContext);
SocketSession session = connector.connect();
HttpClient client = new HttpClient(session);
HttpFuture future = new ClientHttpFuture(context, "/test-show-memory");
HttpFuture res = client.request(future, 10000);
System.out.println();
System.out.println(new String(res.getBodyContent()));
System.out.println();
CloseUtil.close(connector);
}
Aggregations