开发者

How to send content using Netty Http Client?

开发者 https://www.devze.com 2023-04-04 13:20 出处:网络
I\'m using Netty Http client to send requests to a http server. I am re-using the channel and keeping the connection live to reuse it between requests.

I'm using Netty Http client to send requests to a http server.

I am re-using the channel and keeping the connection live to reuse it between requests.

My problem is that although the get method works perfectly, I can' manage to send content in put or post. Following is the code I am using but in my server the http request input stream is empty.

Any ideas?

HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.valueOf(method), uri.t开发者_Python百科oASCIIString());
    if (payLoad != null) {
        request.setContent(ChannelBuffers.wrappedBuffer(payLoad));
    }

Note: payload is a bytearray.

Thanks,

Yair


Since your GET requests work fine, I assume that you write it to channel correctly.

Therefore I would focus on http post:

From http request point of view, you have to specify few more headers in your request. At the very least have a look at Host, Connection, Accept-Encoding, Content-Type and Content-Length.

0

精彩评论

暂无评论...
验证码 换一张
取 消