json post httppost parameter missing for android -
in below code posting json string server. though have writtenn postparams.add(new basicnamevaluepair("json_data", jsonstr)); gives error parameter json_data not passed.
i not sure why giving me error.
orderjsonarray.put(order1); locationjsonarray.put(location1); locationjsonarray.put(location2); order1.put("locations", locationjsonarray); jsonobject ordersobj = new jsonobject(); ordersobj.put("orders", orderjsonarray); string jsonstr = ordersobj.tostring(); string contenttype = "application/json"; list<namevaluepair> postparams = new arraylist<namevaluepair>(); postparams.add(new basicnamevaluepair("json_data", jsonstr)); httpget httpget = null; try { urlencodedformentity entity = new urlencodedformentity(postparams); entity.setcontentencoding(http.utf_8); entity.setcontenttype("application/json"); httppost.setentity(entity); httppost.setheader("content-type", contenttype); httppost.setheader("accept", contenttype); } catch (unsupportedencodingexception e) { } httpresponse httpresponse = httpclient.execute(httppost); inputstream = httpresponse.getentity().getcontent();
use below code
try { httppost httppost1 = null; httpclient httpclient1 = new defaulthttpclient(); if (userchk.equalsignorecase("client")) { httppost1 = new httppost( applicationdata.serviceurl + "/clientlogin"); } else if (userchk.equalsignorecase("driver")) { httppost1 = new httppost( applicationdata.serviceurl + "/driverlogin"); } log.e("9", "9"); // add data list<namevaluepair> namevaluepairs1 = new arraylist<namevaluepair>( 2); namevaluepairs1.add(new basicnamevaluepair( "vemail", email.gettext().tostring())); namevaluepairs1.add(new basicnamevaluepair( "vpassword", password.gettext() .tostring())); httppost1.setentity(new urlencodedformentity( namevaluepairs1)); // execute http post request httpresponse response1 = httpclient1 .execute(httppost1); bufferedreader in1 = new bufferedreader( new inputstreamreader(response1 .getentity().getcontent())); stringbuffer sb1 = new stringbuffer(""); string line1 = ""; while ((line1 = in1.readline()) != null) { sb1.append(line1); } in1.close(); log.e(userchk + " login original data", sb1.tostring()); return sb1.tostring(); } catch (exception e) { return ""; }
Comments
Post a Comment