Jetty7 HttpClient POST problem

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Jetty7 HttpClient POST problem

chazzs
Hello,

I am having some problems crafting and sending a POST to a server via the HttpClient.  I have the Client set up as per the tutorial (http://wiki.eclipse.org/Jetty/Tutorial/HttpClient).  One thing is not clear.  How does one set the parameters for the post?  I am trying to implement a login for an application such that the application can use the same server side script to login as a web client.

I have tried setting the parameters through a call to setRequestContent() to no avail

         AbstractBuffer content = new ByteArrayBuffer("uname=user&pwd=password".getBytes("UTF-8"));
         exchange.setRequestContent(content);

is that the correct way to send POST parameters?  The server side script does not find any parameters.

Thanks for any help.

-chazzs
Reply | Threaded
Open this post in threaded view
|

Re: Jetty7 HttpClient POST problem

ben.vvalk
Hey there,

I was just having the same problem a few minutes ago.

Turns out you need to explicitly set the content type, like this:

exchange.setRequestContentType("application/x-www-form-urlencoded;charset=utf-8");

-- Ben Vandervalk


chazzs wrote
Hello,

I am having some problems crafting and sending a POST to a server via the HttpClient.  I have the Client set up as per the tutorial (http://wiki.eclipse.org/Jetty/Tutorial/HttpClient).  One thing is not clear.  How does one set the parameters for the post?  I am trying to implement a login for an application such that the application can use the same server side script to login as a web client.

I have tried setting the parameters through a call to setRequestContent() to no avail

         AbstractBuffer content = new ByteArrayBuffer("uname=user&pwd=password".getBytes("UTF-8"));
         exchange.setRequestContent(content);

is that the correct way to send POST parameters?  The server side script does not find any parameters.

Thanks for any help.

-chazzs