Correct way to POST JSON data from Android to PHP -


i have seen many tutorials , questions using following method send json object php android. example this wordpress blog, this codeproject tutorial , answers on stackoverflow like these.

all of these tutorials , answers use http header send data(body) php this.

.... // post data: httppost.setheader("json",json.tostring()); .... 

as programmer know headers not meant carry data(body). headers should carry metadata.

so, there correct way send json data php android not involve setting data in header?

if use nativ lib without volley, here dummy httpclient:

httpclient = createhttpclient();  //you wanna use post method. mpost = new httppost(_urlstr);  //head mpost.addheader(new basicheader("content-type", "application/json"));  //body ((httppost) mpost).setentity(new stringentity(jsontext));  //do it. client.execute(mpost); 

try use volley: https://github.com/ogrebgr/android_volley_examples/blob/master/src/com/github/volley_examples/act_simplerequest.java


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -