[解决]
我无法纠正以下错误。请帮我调试问题。我得到错误“无法对ClientCookieEncoder类型的非静态方法编码(Cookie ..)进行静态引用。不推荐使用ClientCookieEncoder,并且文档建议使用编码方法的静态修饰符,这在较新版本中不存在
代码段已从http://netty.io/4.0/xref/io/netty/example/http/snoop/HttpSnoopClient.html
引用 package io.netty.example.http.snoop;
...
import io.netty.handler.codec.http.cookie.ClientCookieEncoder;
import io.netty.handler.codec.http.cookie.DefaultCookie;
..
public final class HttpSnoopClient {
...
// Prepare the HTTP request.
HttpRequest request = new DefaultFullHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getRawPath());
request.headers().set(HttpHeaders.Names.HOST, host);
request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
// Set some example cookies.
request.headers().set(
HttpHeaders.Names.COOKIE,
ClientCookieEncoder.encode(
new DefaultCookie("my-cookie", "foo"),
new DefaultCookie("another-cookie", "bar")));
...
}
答案 0 :(得分:1)
解决方案是:
import io.netty.handler.codec.http.ClientCookieEncoder;
import io.netty.handler.codec.http.DefaultCookie;
….
// Set some example cookies.
request.headers().set(
HttpHeaders.Names.COOKIE,
ClientCookieEncoder.encode(
new DefaultCookie("my-cookie", "foo"),
new DefaultCookie("another-cookie", "bar")));