java - Android send JSON with http get method.result is null -


i'm trying send json http post. serializationed json gson , source code:

public void sendhttppostrequest(final string url, final string json) {      class httpgetasynctask2 extends asynctask<string, void, string> {          private dialog pdialog;         private string response;          @override         protected void onpreexecute() {              super.onpreexecute();              pdialog = new progressdialog(credogenerireba.this);              pdialog.setcancelable(false);              pdialog.show();              pdialog.setcontentview(r.layout.custom_progressdialog);          }          @override         protected string doinbackground(string... params) {             try {                  httppost post = new httppost(url);                  httpresponse resp;                  post.setentity(new stringentity("{ p: " + json + " }",http.utf_8));                  // add headers                  post.addheader("accept", "application/json");                  post.addheader("content-type", "application/json");                  // convert response entity jsonstring                  httpclient httpclient = new defaulthttpclient();                  resp = httpclient.execute(post);                  httpentity httpentity = resp.getentity();                 response = entityutils.tostring(httpentity);                 system.out.println(response  +" response");              } catch (exception e) {                  e.printstacktrace();                }              return null;          }          @override         protected void onpostexecute(string result) {              super.onpostexecute(result);              if (pdialog != null)              {                  pdialog.dismiss();              }              system.out.println(result + "result issss");          }      }      httpgetasynctask2 httpgetasynctask2 = new httpgetasynctask2();      httpgetasynctask2.execute();  } 

i'm calling asynctask function this:

final gson gson = new gson();  myjson = gson.tojson(mainjson); handler.postdelayed(new runnable() {                  @override                 public void run() {                     sendhttppostrequest(                             "myurl",                             gson.tojson(mainjson));                  }             }, 5000); 

i logged myjson string revised correct result(as receive) have problem in http post method. when try run program in onpostexecute result null. wrong don't know if knows solution please me thanks.

nothing wrong, returning "null" in doinbackground(), return doinbackground passed onpostexecute()

to return jsonobject, check out

how return jsonobject doinbackground() method onpostexecute() method on asynctask?

also, read article on asynctask


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -