Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get HttpParams working with Postrequest

I can't get the HttpParams-stuff from the Android-API working.

I just wan't to send some simple Parameters with my Postrequest. Everything is working fine, except for the parameters. The code to set the parameters to the postrequest:

HttpParams params = new BasicHttpParams();
params.setParameter("password", "secret");
params.setParameter("name", "testuser");
postRequest.setParams(params);

It seems that this code isn't adding any parameter at all, as the server always answer, that my request is missing the "name"-parameter.

An example of what is actually working as expected:

ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("name", "testuser"));
postParameters.add(new BasicNameValuePair("password", "secret"));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
postRequest.setEntity(formEntity);

But I would like to use a version of the first example, as it is easier to read and understand.

Any hint is really appreciated!

like image 511
Christoph Haefner Avatar asked Dec 12 '10 22:12

Christoph Haefner


1 Answers

Once I had the same issue, and I solved it the same way as you did... I remember I found some topic about why that wasn't working. It was something about Apache's library implementation on the server side.

Unfortunately I can't find that topic now, but if I were you I would just leave it working and wouldn't worry so much about the "elegance" of the code, cause probably there isn't much you can do, and if you can, it's not practical at all.

like image 161
mdelolmo Avatar answered Sep 30 '22 20:09

mdelolmo