http post - HttpPOST in android -
hi can enlighten me one. i'm stock in it. trying post reportcode web api, didn't receive error when check site see if there reportcode post, haven't seen it. don't know if doing right thing in httppost. here code:
public class dopost extends asynctask<string, void, boolean>
{ exception exception = null; private progressdialog progressdialog; context mcontext = null; bufferedreader in; private string _code;
public dopost(context context, string code) { // todo auto-generated constructor stub mcontext = context; this._code = code; } protected void onpreexecute() { progressdialog = new progressdialog(mcontext); progressdialog.setmessage("uploading...."); progressdialog.show(); progressdialog.setcancelable(false); } @override protected boolean doinbackground(string... arg0) { try{ httpparams httpparameters = new basichttpparams(); httpconnectionparams.setconnectiontimeout(httpparameters, 15000); httpconnectionparams.setsotimeout(httpparameters, 15000); httpclient httpclient = new defaulthttpclient(httpparameters); httppost httppost = new httppost("http://server.serving.com:0727/api/reports"); httppost.setheader("content-type", "application/json"); jsonobject report = new jsonobject(); report.put("reportcode", _code); stringentity entity1 = new stringentity(report.tostring(), http.utf_8); entity1.setcontenttype("application/json"); httppost.setentity(entity1); log.e("reportcode",_code); }catch (exception e){ log.e("clientserverdemo", "error:", e); exception = e; } return true; } @override protected void onpostexecute(boolean valid) { progressdialog.dismiss(); //update ui if(exception != null){ toast.maketext(mcontext, exception.getmessage(), toast.length_long).show(); }else{ toast.maketext(mcontext, "uploaded.", toast.length_short).show(); mcontext.startactivity(new intent(mcontext, s_2nd_main.class)); } }
}
you forgot execute post request:
httpresponse response = httpclient.execute(httppost);
Comments
Post a Comment