Android : Parameter not getting posted POST request Android

on Thursday, September 11, 2014


I am sending a POST request to a Azure based active directory.


Iam sending certain parameters as form encoded to my end point.


Iam doing something like so:-



HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(Constants.Endpoint);

try
{
// Set header with Token
httppost.setHeader("Authorization", Token);

//Add parameters as Form encoded
List <NameValuePair> nvps = new ArrayList <NameValuePair>(5);
nvps.add(new BasicNameValuePair("Comment", comment));

nvps.add(new BasicNameValuePair("Time", time));
nvps.add(new BasicNameValuePair("Location",location));
nvps.add(new BasicNameValuePair("CreatedBy",username));
AbstractHttpEntity entity;
entity = new UrlEncodedFormEntity(nvps, HTTP.UTF_8);
entity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
entity.setContentEncoding("UTF-8");
httppost.setEntity(entity);

//Fetch the response
HttpResponse responsenext = httpclient.execute(httppost);

HttpEntity entitynext = responsenext.getEntity();
AddedResult= EntityUtils.toString(entitynext);


} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


When I debug my application, I get all correct values in nvps. Also all the values except "CreatedBy" parameter are posted properly. But the response I get is as follows:-



{"Id":24,"Location":"Home","Time":"2014-09-11T14:53:29","Comment":null,"CreatedBy":"","Created":"2014-09-11T09:16:50.8886079Z"}


Here the "CreatedBy" value gives a empty String if I send the request from my device.


If I make the same request from Google chrome's Postmaster with same parameters, the "CreatedBy" field is also filled with the value I pass.


Any help would be appreciated


0 comments:

Post a Comment