Sending json object via http post method in android -
its not duplicate.link has been provided old one."http client" has been removed in api23
i want send json object:
{"emailid":"ashish.bhatt@mobimedia.in","address":"naya bans","city":"noida","pincode":"201301","account_number":"91123546374208","bank_name":"axis bank","branch_name":"91123546374208","ifsc_code":"uti0000879"}
to url:
http://10digimr.mobimedia.in/api/mobile_retailer/update_profile how do it? via post method?
method:
post /api/mobile_retailer/update_profile
mandatory key:
{"emailid","address"}
request json:
{"emailid":"ashish.bhatt@mobimedia.in","address":"naya bans","city":"noida","pincode":"201301","account_number":"91123546374208","bank_name":"axis bank","branch_name":"91123546374208","ifsc_code":"uti0000879"}
response:
{"message":"mail send","data":true,"status":200}
define class asynct
, call in oncreate
method using:
asynct asynct = new asynct(); asynct.execute();
class definition:
class asynct extends asynctask<void,void,void>{ @override protected void doinbackground(void... params) { try { url url = new url(""); //enter url here httpurlconnection httpurlconnection = (httpurlconnection)url.openconnection(); httpurlconnection.setdooutput(true); httpurlconnection.setrequestmethod("post"); // here telling post request, can changed "put", "get", "delete" etc. httpurlconnection.setrequestproperty("content-type", "application/json"); // here setting `content-type` data sending `application/json` httpurlconnection.connect(); jsonobject jsonobject = new jsonobject(); jsonobject.put("para_1", "arg_1"); dataoutputstream wr = new dataoutputstream(httpurlconnection.getoutputstream()); wr.writebytes(jsonobject.tostring()); wr.flush(); wr.close(); } catch (malformedurlexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } catch (jsonexception e) { e.printstacktrace(); } return null; } }
Comments
Post a Comment