public class ClientTestHttp {
private final URI uri;
private ChannelBuffer firstMessage;
public ClientTestHttp(URI uri) {
this.uri = uri;
}
public void run() {
// Configure the client.
ClientBootstrap bootstrap = new ClientBootstrap(
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
// Set up the event pipeline factory.
bootstrap.setPipelineFactory(new ClientHttpPipeLineFactory(false));
// Start the connection attempt.
ChannelFuture future = bootstrap.connect(new InetSocketAddress("10.0.0.91", 8181));
// Wait until the connection attempt succeeds or fails.
Channel channel = future.awaitUninterruptibly().getChannel();
if (!future.isSuccess()) {
future.getCause().printStackTrace();
bootstrap.releaseExternalResources();
return;
}
// Prepare the HTTP request.
String sss = uri.getRawPath();
HttpRequest request = new DefaultHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.POST, uri.toASCIIString());
request.setHeader(HttpHeaders.Names.HOST, "10.0.0.91");
request.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
// Set some example cookies.
CookieEncoder httpCookieEncoder = new CookieEncoder(false);
httpCookieEncoder.addCookie("my-cookie", "foo");
httpCookieEncoder.addCookie("another-cookie", "bar");
request.setHeader(HttpHeaders.Names.COOKIE, httpCookieEncoder.encode());
request.setHeader("LAlala", "asdasdasd");
// Send the HTTP request.
request.addHeader("sdasd", "asdasdasdasd".getBytes());
channel.write(request);
System.out.println(channel.isOpen());
// Wait for the server to close the connection.
channel.getCloseFuture().awaitUninterruptibly();
// Shut down executor threads to exit.
bootstrap.releaseExternalResources();
}
public static void main(String[] args) throws Exception {
URI uri = new URI("http://10.0.0.91:8181");
new ClientTestHttp(uri).run();
}
}
嘿。我在向 netty 发送 post 请求时遇到问题。那就是问题所在:
警告:来自下游的意外异常。java.lang.IllegalArgumentException:空文本结论:java.lang.IllegalArgumentException:空文本