How to send request with POST parameters to Netty?

I am trying to send a request with POST parameters to Netty.

I searched API Netty, Google and here (Stack Overflow)

but didn't find a good way to do it. (This could be my terrible search skill mistake: "(If so, I'm sorry)

Is there any API to do this easily?

Or do I have to do this by coding all the parameters and setting it to my content myself?

Please let me know any good way to do this.

+3


source to share


1 answer


Here's an example of how you will upload the file:

https://github.com/netty/netty/tree/master/example/src/main/java/io/netty/example/http/upload

If you don't want to upload the file, just ignore the multipart MIME bit.



Try something like:

HttpRequest httpReq=new DefaultHttpRequest(HttpVersion.HTTP_1_1,HttpMethod.POST,uri);
httpReq.setHeader(HttpHeaders.Names.HOST,host);
httpReq.setHeader(HttpHeaders.Names.CONNECTION,HttpHeaders.Values.KEEP_ALIVE);
httpReq.setHeader(HttpHeaders.Names.ACCEPT_ENCODING,HttpHeaders.Values.GZIP);
httpReq.setHeader(HttpHeaders.Names.CONTENT_TYPE,"application/x-www-form-urlencoded");     
String params="a=b&c=d";
ChannelBuffer cb=ChannelBuffers.copiedBuffer(params,Charset.defaultCharset());
httpReq.setHeader(HttpHeaders.Names.CONTENT_LENGTH,cb.readableBytes());
httpReq.setContent(cb);

      

See Sending POST Parameters with Netty and Why isn't DefaultHttpDataFactory out of editions?

+4


source







All Articles