81,092
社区成员
发帖
与我相关
我的任务
分享
ch.pipeline().addLast(new HttpRequestDecoder());
ch.pipeline().addLast(new HttpServerCodec());
ch.pipeline().addLast(new HttpObjectAggregator(1024*1024));
ch.pipeline().addLast(new JsonObjectDecoder());
ch.pipeline().addLast(new HttpResponseEncoder());
ch.pipeline().addLast(new HttpContentCompressor());
ch.pipeline().addLast(new HttpServerHandler()); //自己写的handler,用来处理业务
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK,
Unpooled.wrappedBuffer(j.toString().getBytes("UTF-8"))); //j为json数据
response.headers().set("Content-Length", res.toString().length());
response.headers().set("Content-Type","application/json");
response.headers().set("Connection", "keep-alive");
ctx.writeAndFlush(response);
ch.pipeline().addLast(new HttpResponseDecoder());
ch.pipeline().addLast(new HttpRequestEncoder());
ch.pipeline().addLast(new clientHttpHandler());
第一次:
DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 400 Bad Request
Content-Length: 12
Content-Type: application/json
Connection: keep-alive
第二次:
DefaultLastHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 12, cap: 12/12, unwrapped: PooledUnsafeDirectByteBuf(ridx: 116, widx: 118, cap: 1024)), decoderResult: success)