【问题标题】:Can netty establish a connect connection with an https link?netty 可以用 https 链接建立连接吗?
【发布时间】:2019-08-19 04:15:32
【问题描述】:

我想用netty完成一个功能

http 发送数据到 netty -> netty 代理数据到目标 https

我启动一个客户端来连接目标链接。

我试过代理到http,没关系

但是当我使用 https 链接时,future.isSuccess() 返回 false

 public void channelRead(ChannelHandlerContext ctx, Object msg) {
        if (msg instanceof FullHttpRequest) {
            FullHttpRequest request = (FullHttpRequest) msg;
            Bootstrap b = new Bootstrap();
            b.group(ctx.channel().eventLoop())
                    .channel(ctx.channel().getClass())
                    .handler(new HttpProxyInitializer(ctx.channel()));
            ChannelFuture f = b.connect("https://xxxx",443);
            outboundChannel = f.channel();
            f.addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) {
                    if (future.isSuccess()) {
                        future.channel().writeAndFlush(msg);
                    } else {
                        ctx.channel().close();
                    }
                }
            });
        }
    }

那么netty connet https不可行吗?

【问题讨论】:

    标签: sockets https proxy netty


    【解决方案1】:

    您的连接方式看起来不正确。

    你会使用:

    b.connect("hostname", 443)
    

    确保您的HttpProxyInitializer 也将SslHandler 添加到ChannelPipeline

    此外,如果事情不起作用,您应该检查future.cause(),因为它将包含一个Throwable,它将提供有关操作失败原因的详细信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-16
      • 2023-03-11
      • 2017-08-13
      • 2013-02-28
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多