Using Android REST API HttpPost sends empty data on Post body -


im trying send data via httppost comes out empty. below if method , httpget part working good. when try add data post body , send, no error , logcat (+ rest web service on other side) show post data empty.

 public void sendphoto(view v) {         final string kookojaurlget = "http://localhost/getdata";         final string kookojaurlpost = "http://localhost/postdata";         new thread(new runnable() {             @override             public void run() {                 httpclient httpclient = new defaulthttpclient();                 try {                     httpresponse getresponse = httpclient.execute(new httpget(kookojaurlget));                     string returnedstuff = entityutils.tostring(getresponse.getentity());                     log.d("debug","http returned " + returnedstuff);                     jsonobject jsonget = new jsonobject(returnedstuff);                     int xxxtime = jsonget.getint("timestamp");                     string xxxnone = jsonget.getstring("nonce");                     string xxxapp = jsonget.getstring("appname");                     string xxxcid = jsonget.getstring("csrftoken");                     log.d("debug","json " + xxxtime + " " + xxxnone + " " + xxxapp + " " + xxxcid);                     jsonobject c = new jsonobject();                     c.put("_username","xxx@gmail.com");                     c.put("_password","123");                     c.put("_timestamp", xxxtime);                     c.put("_nonce", xxxnone);                     c.put("_appname", xxxapp);                     c.put("cid", xxxcid);                     c.put("body", photopost);                     c.put("long", photolong);                     c.put("lat", photolat);                     stringentity sendstuff = new stringentity(c.tostring());                     httppost xxxpost = new httppost(kookojaurlpost);                     xxxpost.setheader("accept", "application/json");                     xxxpost.setheader("content-type", "application/json");                     xxxpost.setheader("accept-encoding", "gzip");                     xxxpost.setentity(sendstuff);                     httpresponse postresponse = httpclient.execute(xxxpost);                     string posttext = entityutils.tostring(postresponse.getentity());                     log.d("debug", "rest post response " + posttext);                 } catch (ioexception e) {                     e.printstacktrace();                 } catch (jsonexception e) {                     e.printstacktrace();                 }             }         }).start();     } 

any appreciated.

i solved problem using "list" instead of jsonobject. here code:

list<namevaluepair> c = new arraylist<namevaluepair>(2); c.add(new basicnamevaluepair("_username", "xxx@gmail.com")); c.add(new basicnamevaluepair("_password", "123")); c.add(new basicnamevaluepair("_timestamp", xxxtime2)); c.add(new basicnamevaluepair("_nonce", xxxnone)); c.add(new basicnamevaluepair("_appname", xxxapp)); c.add(new basicnamevaluepair("cid", xxxcid)); c.add(new basicnamevaluepair("body", photopost)); c.add(new basicnamevaluepair("long", "4524524524")); c.add(new basicnamevaluepair("lat", "242452452")); xxxpost.setentity(new urlencodedformentity(c)); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -