如何使用 Netty Http Client 发送内容?

发布于 2024-12-04 20:47:48 字数 482 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风挽心 2024-12-11 20:47:48

由于您的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文