引用包io.netty.example.proxy中的netty示例,http和https都可以正常工作,即使https消息是乱码。
我想使用netty来执行从代理服务器获取的https消息。
public static void main(String[] args){
Bootstrap b;
EventLoopGroup workerGroup;
ChannelFuture f;
workerGroup = new NioEventLoopGroup();
b = new Bootstrap();
b.group(workerGroup);
b.channel(NioSocketChannel.class);
b.option(ChannelOption.AUTO_READ, false);
b.handler(new HttpForwardHandler());
f = b.connect(ip, port);
}
public class HttpForwardHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelActive(ChannelHandlerContext ctx) {
String content = ""//datagram got from proxy
ByteBuf buf = Unpooled.wrappedBuffer(content .getBytes(Charset.defaultCharset()));
ctx.writeAndFlush(buf )
.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
if (future.isSuccess()) {
ctx.read();
} else {
future.channel().close();
}
}
});
}
@Override
public void channelRead(final ChannelHandlerContext ctx, Object msg) {
//can not get https response here
}
}
版本:netty-all-4.1.9-Final
当我尝试 writeAndFlush 一条 http 消息时,它起作用了,但 https 消息却不起作用。
最佳答案
您应该检查 write futures cause()
以了解为什么它不起作用。
关于java - netty writeAndFlush https 数据报未得到响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44449392/