netty を使用して URL を取得するために netty http クライアントを使用しています。ただし、他のページにリダイレクトしている一部の URL では、クライアントを使用して最終ページのコンテンツを取得できません。応答ハンドラで 302 リダイレクトを処理する方法を知りたいです。
以下は、私の応答ハンドラーの messageReceived 関数で使用されるコードです。
@オーバーライド
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
if (!readingChunks) {
HttpResponse 応答 = (HttpResponse) e.getMessage();
System.out.println("STATUS: " + response.getStatus());
System.out.println("VERSION: " + response.getProtocolVersion());
System.out.println();
if (!response.getHeaderNames().isEmpty()) {
for (文字列名: response.getHeaderNames()) {
for (文字列値: response.getHeaders(name)) {
System.out.println("HEADER: " + 名前 + " = " + 値);
}
}
System.out.println();
}
if (response.isChunked()) {
readingChunks = true;
System.out.println("CHUNKED CONTENT {");
} そうしないと {
ChannelBuffer content = response.getContent();
if (content.readable()) {
System.out.println("CONTENT {");
System.out.println(content.toString(CharsetUtil.UTF_8));
System.out.println("} コンテンツの終わり");
}
}
} そうしないと {
HttpChunk チャンク = (HttpChunk) e.getMessage();
if (chunk.isLast()) {
readingChunks = false;
System.out.println("} チャンクコンテンツの終わり");
} そうしないと {
System.out.print(chunk.getContent().toString(CharsetUtil.UTF_8));
System.out.flush();
}
}
}