0

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.

Yanshof
  • 9,659
  • 21
  • 95
  • 195

1 Answers1

1

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.

Community
  • 1
  • 1
Sephy
  • 50,022
  • 30
  • 123
  • 131