http post connection in android -
i developing application in android.which involves sending data url/server in android application...can tell me how pursue this....thanks in advance tushar
see sample code. helps you.
httpcontext localcontext = new basichttpcontext(); string ret = null; httpclient httpclient = new defaulthttpclient(); httpclient.getparams().setparameter(clientpnames.cookie_policy, cookiepolicy.rfc_2109); httppost httppost = new httppost(url); httpresponse response = null; stringentity tmp = null; httppost.setheader( "accept", "text/html,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); httppost.setheader("content-type", "application/x-www-form-urlencoded"); try { tmp = new stringentity(data, "utf-8"); } catch (unsupportedencodingexception e) { log.e("your app name here", "httputils : unsupportedencodingexception : " + e); } httppost.setentity(tmp); try { response = httpclient.execute(httppost, localcontext); if (response != null) { ret = entityutils.tostring(response.getentity()); log.i("result", ret); } } catch (exception e) { log.e("your app name here", "httputils: " + e); }
Comments
Post a Comment