Hello,

Im converting my code from java HttpURLConnection to
apache.commons.httpclient.

I need to make a Post call passing some parameters. If I use wireshark I
can see that I need to send parameters like this example:


Some_word&param1=param1_value&paramN=paramN_valuers&rs:Command=Render&rs:Format=PDF

What this have in special is this:

# a first word that it is not exactly a parameter, because it doesn have a
value.

# the last values have a ":" character.

In my current solution using java HttpURLConnection I accomplish this
writing to the connection stream like this:

conn = (HttpURLConnection) urlRequest.openConnection();

String params =
"Some_word&param1=param1_value&paramN=paramN_valuers&rs:Command=Render&rs:Format=PDF"

"More init code here......"

DataOutputStream wr = new DataOutputStream(conn.getOutputStream());

// Write data to the connection. This is data being sent to the server

wr.writeBytes(Params);

wr.flush();

wr.close();



So in this way Im writing directly to the stream, and the post message has
exactly the configuration I told.



However, using  apache.commons.httpclient I dont know how to accomplish
this. Right now Im using this code to set parameters:



NameValuePair param1 = new NameValuePair("param_name", "param1_value");

method.setRequestBody( new NameValuePair[] {param1});

 I also tried:

method.addParameter("param_name", "param1_value");



The problem is that, I cant add the first parameter "Some_word", because
using this methods I can only add a pair. I also cant add as a value of the
parameter the character ":", because it is encoded... And I bet this
happens to other speciall characteres.

The result of this call is a first request, where the client is challenged
and then a second request as a "Bad request".

So my question is: Can I write the parameters to the stream as Im doing
using the  java HttpURLConnection object?

Im using commons httclient version 3.0.1. Should I use other version?

thank you,

fwu

Reply via email to