How to use POST in sending data in JSON in android? -
i don't know if i'm doing right way of sending data in json using post. want send single data on jsonobject "reportcode". got far? please tell me what's wrong on code , should need pass data in json. thanks.
public class dopost extends asynctask<string, void, boolean> { exception exception = null; private progressdialog progressdialog; context mcontext = null; bufferedreader in; inputstream is; public dopost(context context) { mcontext = context; } protected void onpreexecute() { progressdialog = new progressdialog(mcontext); progressdialog.setmessage("validating...."); progressdialog.show(); progressdialog.setcancelable(false); } @override protected boolean doinbackground(string... arg0) { jsonobject jobject = new jsonobject(); try{ jobject.put("reportcode","13-t001"); list<namevaluepair> pairs = new arraylist<namevaluepair>(); pairs.add(new basicnamevaluepair("reportdata", jobject.tostring())); defaulthttpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost("http://phsjulchs4.tias.com.ph:1217/api/report"); httppost.setentity(new urlencodedformentity(pairs, "utf-8")); httpresponse httpresponse = httpclient.execute(httppost); httpentity httpentity = httpresponse.getentity(); = httpentity.getcontent(); }catch (exception e){ log.e("clientserverdemo", "error:", e); exception = e; //toast.maketext(getapplicationcontext(), e.getmessage().tostring(), 5).show(); } return true; } @override protected void onpostexecute(boolean valid) { progressdialog.dismiss(); //update ui if(exception != null){ toast.maketext(mcontext, "sent", 6).show(); }else{ // mcontext.startactivity(new intent(mcontext, s_2nd_main.class)); } } }
if see options valid parameters .execute function on defaulthttpclient
, none of them have 1 httppost
object input parameters. that's why experiencing error. try make input parameters correct. hope helps understand issue.
Comments
Post a Comment