Reputation: 9926
I trying to send two parameters to some server. the server is responding to http-post call and the two parameters are Int Some Enum ( that i sending as string )
I want to send the parameters as json:
StringEntity t = new StringEntity("{ \"intValParam\":-100 , \"enumParam\":\"enumValueAsString\" }" , "UTF-8");
httppost.setEntity(t);
httppost.setHeader("content-type", "application/json");
The response that i get is 400 ( bad request )
** There is one more method that i can call that need to have one parameter ... only the int - and this method is working good - so this is not problem from the bad connection or something like that.
Upvotes: 0
Views: 137
Reputation: 50412
You should not try to add your parameters like that. Either use the method setParams
from httpPost or use NameValuePair entities and encode them in your request, like that :
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("userid", "12312"));
nameValuePairs.add(new BasicNameValuePair("sessionid", "234"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
code taken here.
Upvotes: 1