json - Post JsonArray and string parameters using HttpPost in android -
i tried lots of ways send data using httppost haven't succeeded, if knows please help?
my service url :
http://xxxxx/xxx/abc.php?id=xx&name=xxx&data=[{.....}]
its working fine when hit browser code data=[{}] not sending.
my last attempts :
1--->
string serviceurl = "http://xxxxx/xxx/abc.php"; defaulthttpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(serviceurl); httppost.setheader("id", "xx"); httppost.setheader("name", "xxx"); httppost.setheader("content-type", "application/json"); stringentity entity = new stringentity(jsonarr.tostring(), http.utf_8); httppost.setentity(entity); httpresponse httpresponse = httpclient.execute(httppost); httpentity httpentity = httpresponse.getentity(); json_str = entityutils.tostring(httpentity); 2--->
arraylist<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(); namevaluepairs.add(new basicnamevaluepair("id", "xx") ); namevaluepairs.add(new basicnamevaluepair("name", "xxx")); namevaluepairs.add(new basicnamevaluepair("data", jsonarr.tostring())); defaulthttpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(serviceurl); httppost.setheader("content-type", "application/json"); stringentity entity = new stringentity(namevaluepairs.tostring(), http.utf_8); httppost.setentity(entity); httpresponse httpresponse = httpclient.execute(httppost); httpentity httpentity = httpresponse.getentity(); json_str = entityutils.tostring(httpentity); 3--->
arraylist<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(); namevaluepairs.add(new basicnamevaluepair("id", "xx") ); namevaluepairs.add(new basicnamevaluepair("name", "xxx")); defaulthttpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(serviceurl); httppost.setheader("content-type", "application/json"); httppost.setentity(new urlencodedformentity(namevaluepairs)); stringentity entity = new stringentity(jsonarr.tostring(), http.utf_8); httppost.setentity(entity); httpresponse httpresponse = httpclient.execute(httppost); httpentity httpentity = httpresponse.getentity(); json_str = entityutils.tostring(httpentity); output : getting response same got url 'http://xxxxx/xxx/abc.php?id=xx&name=xxx' (without data parameter) on browser, thing means data=[{}] not sending simple_string_parameters code.
tried lot of way send data using httppost not succeed
=> yes obvious webservice url following method, not post.
http://xxxxx/xxx/abc.php?id=xx&name=xxx&data=[{.....}]
so suggest try httpget method instead of httppost.
check answer adding parameters http request in android?
Comments
Post a Comment