0
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 への投稿リクエストの送信に問題があります。それが問題です:

警告: ダウンストリームからの予期しない例外。java.lang.IllegalArgumentException: 空のテキスト 結論: java.lang.IllegalArgumentException: 空のテキスト

4

1 に答える 1

0

パッケージのHttpUploadClient例を参照してください。org.jboss.netty.example.http.upload

http://netty.io/3.6/xref/org/jboss/netty/example/http/upload/package-summary.html

于 2013-03-19T08:50:05.527 に答える