I am stuck in a really, really basic problem: using the HttpRequest to POST JSON bit for the server using Netty.
As soon as the channel is connected, I prepare the request as follows:
HttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.POST, postPath); request.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json"); String json = "{\"foo\":\"bar\"}"; ChannelBuffer buffer = ChannelBuffers.copiedBuffer(json, CharsetUtil.UTF_8); request.setContent(buffer); channel.write(request); System.out.println("sending on channel: " + json);
The last line prints {"foo":"bar"} , which is valid JSON.
However, in fact, a simple echo server that I wrote in Python using Flask shows a request, but it does not have a body or json field, for example, the body cannot be parsed correctly in JSON.
When I just use curl to send the same data, then the echo server correctly finds and parses JSON:
curl --header "Content-Type: application/json" -d '{"foo":"bar"}' -X POST http://localhost:5000/post_path
My pipeline in Netty is formed using:
return Channels.pipeline( new HttpClientCodec(), new MyUpstreamHandler(...));
Where MyUpstreamHandler extends SimpleChannelUpstreamHandler and tries to send an HttpRequest after connecting the channel.
Again, I have a complete loss. Any help would be greatly appreciated.