如何使用 Netty Http Client 发送内容?
我正在使用 Netty Http 客户端向 http 服务器发送请求。
我正在重复使用该通道并保持连接处于活动状态,以便在请求之间重复使用它。
我的问题是,虽然 get 方法工作得很好,但我无法设法在 put 或 post 中发送内容。以下是我正在使用的代码,但在我的服务器中,http 请求输入流为空。
有什么想法吗?
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.valueOf(method), uri.toASCIIString());
if (payLoad != null) {
request.setContent(ChannelBuffers.wrappedBuffer(payLoad));
}
注意:有效负载是一个字节数组。
谢谢,
亚伊尔
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.toASCIIString());
if (payLoad != null) {
request.setContent(ChannelBuffers.wrappedBuffer(payLoad));
}
Note: payload is a bytearray.
Thanks,
Yair
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您的 GET 请求工作正常,我假设您将其正确写入通道。
因此,我将重点关注http post:
从http请求的角度来看,您必须在请求中指定更多标头。至少看看主机、连接、接受编码、内容类型和 >内容长度。
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.